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

[14.0][IMP] rma_delivery: add default_carrier_in_id #302

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
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 rma_delivery/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "RMA delivery integration",
"version": "14.0.1.0.0",
"version": "14.0.1.1.0",
"license": "LGPL-3",
"category": "RMA",
"summary": "RMA default carrier on operation" "in odoo",
Expand Down
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,
[
(
"rma.operation",
"rma_operation",
"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