delivery_carrier_partner_account: transfer carrier account to delivery order on SO confirmation
This commit is contained in:
parent
b33f25c688
commit
1ef0102dd2
4 changed files with 38 additions and 6 deletions
|
|
@ -19,7 +19,7 @@
|
||||||
#
|
#
|
||||||
{
|
{
|
||||||
"name": "Carrier Accounts by Partner",
|
"name": "Carrier Accounts by Partner",
|
||||||
"version": "18.0.0.1.2",
|
"version": "18.0.0.1.3",
|
||||||
"summary": "Add one or many carrier accounts per partner",
|
"summary": "Add one or many carrier accounts per partner",
|
||||||
"category": "Delivery",
|
"category": "Delivery",
|
||||||
"author": "Bemade Inc.",
|
"author": "Bemade Inc.",
|
||||||
|
|
|
||||||
|
|
@ -250,9 +250,6 @@ class CarrierAccountMixin(models.AbstractModel):
|
||||||
"carrier_account_ids.delivery_carrier_id"
|
"carrier_account_ids.delivery_carrier_id"
|
||||||
)
|
)
|
||||||
|
|
||||||
def _on_carrier_fields_changed(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@api.constrains("delivery_billing_mode", "carrier_id", "carrier_account_id")
|
@api.constrains("delivery_billing_mode", "carrier_id", "carrier_account_id")
|
||||||
def _check_carrier_account(self):
|
def _check_carrier_account(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
|
|
@ -285,4 +282,4 @@ class CarrierAccountMixin(models.AbstractModel):
|
||||||
elif rec.delivery_billing_mode == "third party":
|
elif rec.delivery_billing_mode == "third party":
|
||||||
raise UserError(
|
raise UserError(
|
||||||
f"Third party carrier account cannot belong to sender or recipient. Current object: {rec}"
|
f"Third party carrier account cannot belong to sender or recipient. Current object: {rec}"
|
||||||
)
|
)
|
||||||
|
|
@ -46,3 +46,14 @@ class SalesOrder(models.Model):
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def action_confirm(self):
|
||||||
|
res = super().action_confirm()
|
||||||
|
self.picking_ids.write(
|
||||||
|
{
|
||||||
|
"delivery_billing_mode": self.delivery_billing_mode,
|
||||||
|
"carrier_account_id": self.carrier_account_id
|
||||||
|
and self.carrier_account_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return res
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from .test_carrier_account_common import TestCarrierAccountCommon
|
from .test_carrier_account_common import TestCarrierAccountCommon
|
||||||
from odoo.tests import Form
|
from odoo.tests import Form
|
||||||
from odoo import Command
|
from odoo import Command, api
|
||||||
|
|
||||||
|
|
||||||
class TestSalesOrder(TestCarrierAccountCommon):
|
class TestSalesOrder(TestCarrierAccountCommon):
|
||||||
|
|
@ -76,6 +76,30 @@ class TestSalesOrder(TestCarrierAccountCommon):
|
||||||
"The carrier account should belong to the recipient (sale order shipping address)",
|
"The carrier account should belong to the recipient (sale order shipping address)",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_stock_picking_inherits_carrier_info(self):
|
||||||
|
order = self.env["sale.order"].create(
|
||||||
|
{
|
||||||
|
"partner_id": self.client_partner.id,
|
||||||
|
"partner_shipping_id": self.client_partner.id,
|
||||||
|
"order_line": [
|
||||||
|
Command.create(
|
||||||
|
{"product_id": self.env.ref("product.product_delivery_01").id}
|
||||||
|
)
|
||||||
|
],
|
||||||
|
"carrier_id": self.delivery_carrier_1.id,
|
||||||
|
"delivery_billing_mode": "collect",
|
||||||
|
"carrier_account_id": self.client_account_1.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
order.action_confirm()
|
||||||
|
self.env.flush_all()
|
||||||
|
|
||||||
|
picking = order.picking_ids
|
||||||
|
self.assertEqual(picking.carrier_id, order.carrier_id)
|
||||||
|
self.assertEqual(picking.delivery_billing_mode, order.delivery_billing_mode)
|
||||||
|
self.assertEqual(picking.carrier_account_id, order.carrier_account_id)
|
||||||
|
|
||||||
|
@api.returns("delivery.carrier.wizard")
|
||||||
def _get_shipping_wizard(self, order):
|
def _get_shipping_wizard(self, order):
|
||||||
wizard_action = order.action_open_delivery_wizard()
|
wizard_action = order.action_open_delivery_wizard()
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue