delivery_carrier_partner_account: add choose delivery wizard code and tests
This commit is contained in:
parent
d99acaa3ec
commit
9b882ec7f8
12 changed files with 175 additions and 84 deletions
|
|
@ -1 +1,2 @@
|
|||
from . import models
|
||||
from . import wizard
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
"views/res_partner_views.xml",
|
||||
"views/delivery_carrier_views.xml",
|
||||
"views/delivery_carrier_account_views.xml",
|
||||
"wizard/choose_delivery_carrier_views.xml",
|
||||
],
|
||||
"assets": {},
|
||||
"installable": True,
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ class CarrierAccountMixin(models.AbstractModel):
|
|||
Third Party: A third party will be billed (account information needed)
|
||||
"""
|
||||
),
|
||||
tracking=1,
|
||||
string="Delivery Billing Mode",
|
||||
)
|
||||
|
||||
|
|
@ -156,10 +155,12 @@ class CarrierAccountMixin(models.AbstractModel):
|
|||
if (
|
||||
not rec.delivery_billing_mode
|
||||
or rec.delivery_billing_mode == "no charge"
|
||||
) and rec.carrier_account_id:
|
||||
raise UserError(
|
||||
_("No carrier account should be set for no charge delivery.")
|
||||
)
|
||||
):
|
||||
if rec.carrier_account_id:
|
||||
raise UserError(
|
||||
_("No carrier account should be set for no charge delivery.")
|
||||
)
|
||||
continue
|
||||
# We allow empty carrier account for third party since we can't always
|
||||
# set it automatically.
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -1 +1,4 @@
|
|||
from . import test_carrier_account_common
|
||||
from . import test_carrier_account_mixin
|
||||
from . import test_choose_delivery_carrier
|
||||
from . import test_sale_order
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
from odoo.tests import TransactionCase, tagged
|
||||
from odoo import Command
|
||||
|
||||
|
||||
@tagged("-at_install", "post_install")
|
||||
class TestCarrierAccountCommon(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.client_partner = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Test partner",
|
||||
}
|
||||
)
|
||||
cls.random_partner = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Third Party",
|
||||
}
|
||||
)
|
||||
cls.delivery_carrier_1 = cls.env.ref("delivery.free_delivery_carrier")
|
||||
cls.delivery_carrier_2 = cls.env.ref("delivery.delivery_local_delivery")
|
||||
cls.client_account_1 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.client_partner.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_1.id,
|
||||
"account_number": "1234567890",
|
||||
}
|
||||
)
|
||||
cls.client_account_2 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.client_partner.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_2.id,
|
||||
"account_number": "0987654321",
|
||||
}
|
||||
)
|
||||
cls.sender_account_1 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.env.company.partner_id.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_1.id,
|
||||
"account_number": "hijklmn",
|
||||
}
|
||||
)
|
||||
cls.sender_account_2 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.env.company.partner_id.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_2.id,
|
||||
"account_number": "abcdefg",
|
||||
}
|
||||
)
|
||||
cls.third_party_account_1 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.random_partner.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_1.id,
|
||||
"account_number": "8910111213",
|
||||
}
|
||||
)
|
||||
cls.third_party_account_2 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.random_partner.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_2.id,
|
||||
"account_number": "zzzzzzzzz",
|
||||
}
|
||||
)
|
||||
|
||||
def _create_sale_order(self, billing_mode, carrier, account):
|
||||
vals = {
|
||||
"partner_id": self.client_partner.id,
|
||||
"carrier_id": carrier.id,
|
||||
"delivery_billing_mode": billing_mode,
|
||||
"order_line": [
|
||||
Command.create(
|
||||
{
|
||||
"product_id": self.env.ref("product.product_product_4").id,
|
||||
}
|
||||
)
|
||||
],
|
||||
}
|
||||
if account:
|
||||
vals["carrier_account_id"] = account.id
|
||||
return self.env["sale.order"].create(vals)
|
||||
|
|
@ -1,68 +1,8 @@
|
|||
from odoo.tests import TransactionCase, tagged, mute_logger
|
||||
from odoo import Command
|
||||
from .test_carrier_account_common import TestCarrierAccountCommon
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
@tagged("-at_install", "post_install")
|
||||
class TestCarrierAccountMixin(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.client_partner = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Test partner",
|
||||
}
|
||||
)
|
||||
cls.random_partner = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Third Party",
|
||||
}
|
||||
)
|
||||
cls.delivery_carrier_1 = cls.env.ref("delivery.free_delivery_carrier")
|
||||
cls.delivery_carrier_2 = cls.env.ref("delivery.delivery_local_delivery")
|
||||
cls.client_account_1 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.client_partner.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_1.id,
|
||||
"account_number": "1234567890",
|
||||
}
|
||||
)
|
||||
cls.client_account_2 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.client_partner.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_2.id,
|
||||
"account_number": "0987654321",
|
||||
}
|
||||
)
|
||||
cls.sender_account_1 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.env.company.partner_id.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_1.id,
|
||||
"account_number": "hijklmn",
|
||||
}
|
||||
)
|
||||
cls.sender_account_2 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.env.company.partner_id.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_2.id,
|
||||
"account_number": "abcdefg",
|
||||
}
|
||||
)
|
||||
cls.third_party_account_1 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.random_partner.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_1.id,
|
||||
"account_number": "8910111213",
|
||||
}
|
||||
)
|
||||
cls.third_party_account_2 = cls.env["delivery.carrier.account"].create(
|
||||
{
|
||||
"partner_id": cls.random_partner.id,
|
||||
"delivery_carrier_id": cls.delivery_carrier_2.id,
|
||||
"account_number": "zzzzzzzzz",
|
||||
}
|
||||
)
|
||||
|
||||
class TestCarrierAccountMixin(TestCarrierAccountCommon):
|
||||
def test_compute_account_collect_order(self):
|
||||
order = self._create_sale_order(
|
||||
"collect",
|
||||
|
|
@ -145,20 +85,3 @@ class TestCarrierAccountMixin(TransactionCase):
|
|||
self._create_sale_order(
|
||||
"third party", self.delivery_carrier_1, self.sender_account_1
|
||||
)
|
||||
|
||||
def _create_sale_order(self, billing_mode, carrier, account):
|
||||
vals = {
|
||||
"partner_id": self.client_partner.id,
|
||||
"carrier_id": carrier.id,
|
||||
"delivery_billing_mode": billing_mode,
|
||||
"order_line": [
|
||||
Command.create(
|
||||
{
|
||||
"product_id": self.env.ref("product.product_product_4").id,
|
||||
}
|
||||
)
|
||||
],
|
||||
}
|
||||
if account:
|
||||
vals["carrier_account_id"] = account.id
|
||||
return self.env["sale.order"].create(vals)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
from .test_carrier_account_common import TestCarrierAccountCommon
|
||||
|
||||
|
||||
class TestChooseDeliveryCarrier(TestCarrierAccountCommon):
|
||||
def test_sale_order_add_transport(self):
|
||||
order = self.env["sale.order"].create(
|
||||
{
|
||||
"partner_id": self.client_partner.id,
|
||||
}
|
||||
)
|
||||
wizard_action = order.action_open_delivery_wizard()
|
||||
|
||||
wizard = (
|
||||
self.env[wizard_action["res_model"]]
|
||||
.with_context(wizard_action["context"])
|
||||
.create({})
|
||||
)
|
||||
wizard.carrier_id = self.delivery_carrier_1
|
||||
wizard.delivery_billing_mode = "collect"
|
||||
wizard.button_confirm()
|
||||
self.assertEqual(order.carrier_id, self.delivery_carrier_1)
|
||||
self.assertEqual(order.carrier_account_id, self.client_account_1)
|
||||
self.assertEqual(order.delivery_billing_mode, "collect")
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
from .test_carrier_account_common import TestCarrierAccountCommon
|
||||
|
||||
|
||||
class TestSalesOrder(TestCarrierAccountCommon):
|
||||
def test_sales_order_creation_with_default_account(self):
|
||||
self.client_partner.property_delivery_carrier_id = self.delivery_carrier_1
|
||||
self.client_partner.default_carrier_account_id = self.client_account_1
|
||||
self.env["sale.order"].create({"partner_id": self.client_partner.id})
|
||||
11
delivery_carrier_partner_account/views/sale_order_views.xml
Normal file
11
delivery_carrier_partner_account/views/sale_order_views.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="sale_order_view_form" model="ir.ui.view">
|
||||
<field name="name">sale.order.view.form</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="arch" type="xml">
|
||||
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
1
delivery_carrier_partner_account/wizard/__init__.py
Normal file
1
delivery_carrier_partner_account/wizard/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import choose_delivery_carrier
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
from odoo import models, fields
|
||||
|
||||
|
||||
class ChooseDeliveryCarrier(models.TransientModel):
|
||||
"""Add options to select the carrier account and billing mode."""
|
||||
|
||||
_inherit = ["choose.delivery.carrier", "carrier.account.mixin"]
|
||||
_name = "choose.delivery.carrier"
|
||||
|
||||
sender_id = fields.Many2one(related="company_id.partner_id")
|
||||
recipient_id = fields.Many2one(related="partner_id")
|
||||
|
||||
def button_confirm(self):
|
||||
res = super().button_confirm()
|
||||
extra_vals = {}
|
||||
if self.delivery_billing_mode:
|
||||
extra_vals.update(delivery_billing_mode=self.delivery_billing_mode)
|
||||
if self.carrier_account_id:
|
||||
extra_vals.update(carrier_account_id=self.carrier_account_id)
|
||||
self.order_id.write(extra_vals)
|
||||
return res
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="choose_delivery_carrier_view_form" model="ir.ui.view">
|
||||
<field name="name">choose.delivery.carrier.view.form</field>
|
||||
<field name="model">choose.delivery.carrier</field>
|
||||
<field name="inherit_id" ref="delivery.choose_delivery_carrier_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="carrier_id" position="after">
|
||||
<field name="delivery_billing_mode"/>
|
||||
<field name="valid_carrier_account_ids" invisible="1"/>
|
||||
<field
|
||||
name="carrier_account_id"
|
||||
domain="[('id', 'in', valid_carrier_account_ids)]"
|
||||
/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Reference in a new issue