Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] delivery_package_number: port missing commits from 15 #890

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion delivery_package_number/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Contributors

* Pedro M. Baeza
* David Vidal
* Marçal Isern
* Carlos Roca
* Sergio Teruel


* `Sygel <https://www.sygel.es>`_:
Expand Down
2 changes: 0 additions & 2 deletions delivery_package_number/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"reports/report_package_number.xml",
"views/stock_picking_type_views.xml",
"views/stock_picking_views.xml",
"wizard/stock_immediate_transfer_views.xml",
"wizard/stock_backorder_confirmation_views.xml",
"wizard/stock_number_package_validate_wiz_view.xml",
],
}
26 changes: 20 additions & 6 deletions delivery_package_number/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.tools import config


class StockPicking(models.Model):
Expand All @@ -15,6 +16,7 @@
default=0,
copy=False,
)
ask_number_of_packages = fields.Boolean(compute="_compute_ask_number_of_packages")

@api.depends("package_ids")
def _compute_number_of_packages(self):
Expand All @@ -37,24 +39,36 @@
),
}

def _check_set_number_of_packages(self):
def _compute_ask_number_of_packages(self):
"""To Know if is needed raise wizard to ask user by package number"""
for picking in self:
picking.ask_number_of_packages = bool(
picking.carrier_id
and not picking.package_ids
or picking.picking_type_id.force_set_number_of_packages
)

def _get_pickings_to_set_number_of_packages(self):
"""Get pickings that needed raise wizard to fill number of packages"""
pickings_to_set_number_of_packages = self.browse()
for picking in self:
if (
picking.picking_type_id.force_set_number_of_packages
and not picking.number_of_packages
):
if not picking.number_of_packages:
pickings_to_set_number_of_packages |= picking
return pickings_to_set_number_of_packages

def _pre_action_done_hook(self):
res = super()._pre_action_done_hook()
test_condition = not config["test_enable"] or self.env.context.get(
"test_delivery_package_number"
)
if (
res
and test_condition
and isinstance(res, bool)
and any(picking.ask_number_of_packages for picking in self)
and not self.env.context.get("bypass_set_number_of_packages")
):
pickings_to_set_nop = self._check_set_number_of_packages()
pickings_to_set_nop = self._get_pickings_to_set_number_of_packages()

Check warning on line 71 in delivery_package_number/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_package_number/models/stock_picking.py#L71

Added line #L71 was not covered by tests
if pickings_to_set_nop:
return pickings_to_set_nop._action_generate_number_of_packages_wizard()
return res
2 changes: 1 addition & 1 deletion delivery_package_number/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

* Pedro M. Baeza
* David Vidal
* Marçal Isern
* Carlos Roca
* Sergio Teruel


* `Sygel <https://www.sygel.es>`_:
Expand Down
1 change: 1 addition & 0 deletions delivery_package_number/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_stock_number_package_validate_wizard,access.stock.number.package.validate.wizard,model_stock_number_package_validate_wizard,stock.group_stock_user,1,1,1,0
access_stock_number_package_validate_line_wizard,access.stock.number.package.validate.line.wizard,model_stock_number_package_validate_line_wizard,stock.group_stock_user,1,1,1,0
2 changes: 1 addition & 1 deletion delivery_package_number/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza</li>
<li>David Vidal</li>
<li>Marçal Isern</li>
<li>Carlos Roca</li>
<li>Sergio Teruel</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def test_backorder(self):
picking = order.picking_ids
picking.move_ids.quantity_done = 2
picking.number_of_packages = 2
action = picking.button_validate()
action = picking.with_context(
test_delivery_package_number=True
).button_validate()
backorder_wizard = Form(
self.env[action["res_model"]].with_context(**action["context"])
).save()
Expand Down
1 change: 0 additions & 1 deletion delivery_package_number/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import stock_number_package_mixin
from . import stock_inmediate_transfer
from . import stock_backorder_confirmation
from . import stock_number_package_validate_wiz
18 changes: 2 additions & 16 deletions delivery_package_number/wizard/stock_backorder_confirmation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,10 @@


class StockBackorderConfirmation(models.TransientModel):
_inherit = ["stock.backorder.confirmation", "stock.number.package.mixin"]
_name = "stock.backorder.confirmation"
_inherit = "stock.backorder.confirmation"

def process(self):
if self.number_of_packages:
self.pick_ids.write({"number_of_packages": self.number_of_packages})
# put context key for avoiding `base_delivery_carrier_label` auto-packaging feature
res = super(
return super(
StockBackorderConfirmation, self.with_context(set_default_package=False)
).process()
if self.print_package_label:
report = (
self.pick_ids.picking_type_id.report_number_of_packages
or self.env.ref(
"delivery_package_number.action_delivery_package_number_report"
)
)
report_action = report.report_action(self.pick_ids)
report_action.update({"close_on_report_download": True})
return report_action
return res

This file was deleted.

26 changes: 0 additions & 26 deletions delivery_package_number/wizard/stock_immediate_transfer_views.xml

This file was deleted.

18 changes: 2 additions & 16 deletions delivery_package_number/wizard/stock_inmediate_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,10 @@


class StockImmediateTransfer(models.TransientModel):
_inherit = ["stock.immediate.transfer", "stock.number.package.mixin"]
_name = "stock.immediate.transfer"
_inherit = "stock.immediate.transfer"

def process(self):
if self.number_of_packages:
self.pick_ids.write({"number_of_packages": self.number_of_packages})
# put context key for avoiding `base_delivery_carrier_label` auto-packaging feature
res = super(
return super(
StockImmediateTransfer, self.with_context(set_default_package=False)
).process()
if self.print_package_label:
report = (
self.pick_ids.picking_type_id.report_number_of_packages
or self.env.ref(
"delivery_package_number.action_delivery_package_number_report"
)
)
report_action = report.report_action(self.pick_ids)
report_action.update({"close_on_report_download": True})
return report_action
return res
32 changes: 0 additions & 32 deletions delivery_package_number/wizard/stock_number_package_mixin.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
# Copyright 2023 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo import api, fields, models


class StockNumberPackageValidateWiz(models.TransientModel):
_inherit = "stock.number.package.mixin"
_name = "stock.number.package.validate.wizard"
_description = "Wizard to force set number of pickings when validate"

pick_ids = fields.Many2many("stock.picking", "stock_picking_number_package_rel")
number_of_packages = fields.Integer(
help="Set the number of packages for this picking(s)",
)
stock_number_package_validation_line_ids = fields.One2many(
comodel_name="stock.number.package.validate.line.wizard",
inverse_name="wiz_id",
compute="_compute_stock_number_package_validation_line_ids",
readonly=False,
store=True,
)
print_package_label = fields.Boolean(
compute="_compute_print_package_label", readonly=False, store=True
)

@api.depends("pick_ids")
def _compute_print_package_label(self):
for item in self:
item.print_package_label = item.pick_ids.picking_type_id.print_label

Check warning on line 28 in delivery_package_number/wizard/stock_number_package_validate_wiz.py

View check run for this annotation

Codecov / codecov/patch

delivery_package_number/wizard/stock_number_package_validate_wiz.py#L28

Added line #L28 was not covered by tests

@api.depends("pick_ids")
def _compute_stock_number_package_validation_line_ids(self):
for wiz in self:
if len(wiz.pick_ids) <= 1:
wiz.stock_number_package_validation_line_ids = False

Check warning on line 34 in delivery_package_number/wizard/stock_number_package_validate_wiz.py

View check run for this annotation

Codecov / codecov/patch

delivery_package_number/wizard/stock_number_package_validate_wiz.py#L34

Added line #L34 was not covered by tests
else:
wiz.stock_number_package_validation_line_ids = [
fields.Command.create({"picking_id": picking.id})
for picking in wiz.pick_ids
]

def process(self):
if self.number_of_packages:
self.pick_ids.write({"number_of_packages": self.number_of_packages})
# put context key for avoiding `base_delivery_carrier_label` auto-packaging feature
res = self.pick_ids.with_context(
self.pick_ids.with_context(

Check warning on line 45 in delivery_package_number/wizard/stock_number_package_validate_wiz.py

View check run for this annotation

Codecov / codecov/patch

delivery_package_number/wizard/stock_number_package_validate_wiz.py#L45

Added line #L45 was not covered by tests
set_default_package=False, bypass_set_number_of_packages=True
).button_validate()
if self.print_package_label:
self._print_package_label()
return res
return self._print_package_label()

Check warning on line 49 in delivery_package_number/wizard/stock_number_package_validate_wiz.py

View check run for this annotation

Codecov / codecov/patch

delivery_package_number/wizard/stock_number_package_validate_wiz.py#L49

Added line #L49 was not covered by tests

def _print_package_label(self):
"""Method to be inherited by other modules and allow print the report in
Expand All @@ -36,3 +63,16 @@
report_action = report.report_action(self.pick_ids)
report_action.update({"close_on_report_download": True})
return report_action


class StockNumberPackageValidateLineWizLine(models.TransientModel):
_name = "stock.number.package.validate.line.wizard"
_description = "Stock Number Package Lines Wizard"

wiz_id = fields.Many2one(
comodel_name="stock.number.package.validate.wizard", readonly=True
)
picking_id = fields.Many2one(comodel_name="stock.picking")
number_of_packages = fields.Integer(
related="picking_id.number_of_packages", readonly=False
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,29 @@
<field name="model">stock.number.package.validate.wizard</field>
<field name="arch" type="xml">
<form string="Set number of packages">
<field name="pick_ids" invisible="1" />
<group>
<field name="number_of_packages" />
<field
name="number_of_packages"
attrs="{'invisible': [('stock_number_package_validation_line_ids', '!=', [])]}"
/>
</group>
<group>
<field
name="stock_number_package_validation_line_ids"
attrs="{'invisible': [('stock_number_package_validation_line_ids', '=', [])]}"
nolabel="1"
>
<tree create="0" delete="0" editable="1">
<field
name="picking_id"
options="{'no_open': True}"
readonly="1"
force_save="1"
/>
<field name="number_of_packages" />
</tree>
</field>
</group>
<footer>
<button
Expand Down
Loading