Skip to content

Commit

Permalink
[IMP] rma_delivery: add default in carrier
Browse files Browse the repository at this point in the history
  • Loading branch information
mariadforgeflow committed Dec 27, 2022
1 parent 23d00a1 commit 8ede7d2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
20 changes: 20 additions & 0 deletions rma_delivery/migrations/14.0.1.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2022 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
if openupgrade.column_exists(env.cr, "delivery_carrier", "default_carrier_id"):
openupgrade.rename_fields(
env,
[
(
"delivery.carrier",
"delivery_carrier",
"default_carrier_id",
"default_carrier_out_id",
)
],
)
14 changes: 12 additions & 2 deletions rma_delivery/models/rma_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ class RmaOperation(models.Model):

_inherit = "rma.operation"

default_carrier_id = fields.Many2one(
comodel_name="delivery.carrier", string="Default carrier", required=False
default_carrier_in_id = fields.Many2one(
comodel_name="delivery.carrier",
string="Default Recepit carrier",
required=False,
domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]",
)

default_carrier_out_id = fields.Many2one(
comodel_name="delivery.carrier",
string="Default Delivery carrier",
required=False,
domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]",
)
2 changes: 1 addition & 1 deletion rma_delivery/tests/test_rma_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUpClass(cls):
)
cls.rma_cust_replace_op_id.write(
{
"default_carrier_id": cls.carrier_id.id,
"default_carrier_out_id": cls.carrier_id.id,
}
)

Expand Down
5 changes: 4 additions & 1 deletion rma_delivery/views/rma_operation_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
<field name="model">rma.operation</field>
<field name="inherit_id" ref="rma.rma_operation_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='receipt_policy']" position="after">
<field name="default_carrier_in_id" options="{'no_create': True}" />
</xpath>
<xpath expr="//field[@name='delivery_policy']" position="after">
<field name="default_carrier_id" options="{'no_create': True}" />
<field name="default_carrier_out_id" options="{'no_create': True}" />
</xpath>
</field>
</record>
Expand Down
9 changes: 7 additions & 2 deletions rma_delivery/wizard/rma_make_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ class RmaMakePicking(models.TransientModel):
def _create_picking(self):
res = super()._create_picking()
for line in self.mapped("item_ids.line_id").filtered(
lambda x: x.operation_id.default_carrier_id
lambda x: x.operation_id.default_carrier_out_id
):
pickings = line._get_out_pickings().filtered(lambda x: not x.carrier_id)
pickings.write({"carrier_id": line.operation_id.default_carrier_id.id})
pickings.write({"carrier_id": line.operation_id.default_carrier_out_id.id})
for line in self.mapped("item_ids.line_id").filtered(
lambda x: x.operation_id.default_carrier_in_id
):
pickings = line._get_in_pickings().filtered(lambda x: not x.carrier_id)
pickings.write({"carrier_id": line.operation_id.default_carrier_in_id.id})
return res

0 comments on commit 8ede7d2

Please sign in to comment.