Define default shipment cost method by party

issue10160
review316991002
This commit is contained in:
Maxime Richez committed 2021-10-11 22:41:31 +02:00
1 parent d10aac3893
commit 2958984614
8 files changed
+91 -1

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Define default shipment cost method by party
* Add cost method to shipment
Version 6.0.0 - 2021-05-03
+4
View File
@@ -2,6 +2,8 @@
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool
from . import party
from . import account
from . import sale
from . import stock
@@ -9,6 +11,8 @@ from . import stock
def register():
Pool.register(
party.Party,
party.PartySaleMethod,
account.InvoiceLine,
sale.Configuration,
sale.ConfigurationSaleMethod,
+45
View File
@@ -0,0 +1,45 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of this
# repository contains the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import PoolMeta, Pool
from trytond.transaction import Transaction
from trytond.modules.sale.party import get_sale_methods
class Party(metaclass=PoolMeta):
__name__ = 'party.party'
sale_shipment_cost_method = fields.MultiValue(fields.Selection(
'get_sale_shipment_cost_method', "Shipment Cost Method",
help="The default shipment cost method for the customer.\n"
"Leave empty to use the default value from the configuration."))
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field == 'sale_shipment_cost_method':
return pool.get('party.party.sale_method')
return super().multivalue_model(field)
get_sale_shipment_cost_method = get_sale_methods('shipment_cost_method')
@classmethod
def copy(cls, parties, default=None):
context = Transaction().context
default = default.copy() if default else {}
if context.get('_check_access'):
fields = ['sale_shipment_cost_method']
default_values = cls.default_get(fields, with_rec_name=False)
for fname in fields:
default.setdefault(fname, default_values.get(fname))
return super().copy(parties, default=default)
class PartySaleMethod(metaclass=PoolMeta):
__name__ = 'party.party.sale_method'
sale_shipment_cost_method = fields.Selection(
'get_sale_shipment_cost_method', "Sale Shipment Cost Method")
get_sale_shipment_cost_method = get_sale_methods('shipment_cost_method')
+24
View File
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="party_view_form">
<field name="model">party.party</field>
<field name="inherit" ref="party.party_view_form"/>
<field name="name">party_form</field>
</record>
<record model="ir.model.field.access" id="access_party_sale_shipment_cost_method">
<field name="field" search="[('model.model', '=', 'party.party'), ('name', '=', 'sale_shipment_cost_method')]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
</record>
<record model="ir.model.field.access" id="access_party_sale_shipment_cost_method_group_sale">
<field name="field" search="[('model.model', '=', 'party.party'), ('name', '=', 'sale_shipment_cost_method')]"/>
<field name="group" ref="sale.group_sale"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
</record>
</data>
</tryton>
+4
View File
@@ -153,6 +153,10 @@ class Sale(metaclass=PoolMeta):
self.carrier = self.available_carriers[0]
elif not self.available_carriers:
self.carrier = None
if self.party and self.party.sale_shipment_cost_method:
self.shipment_cost_method = self.party.sale_shipment_cost_method
else:
self.shipment_cost_method = self.default_shipment_cost_method()
@fields.depends('carrier', methods=['on_change_with_available_carriers'])
def on_change_shipment_party(self):
+3 -1
View File
@@ -47,6 +47,7 @@ Create customer::
>>> Party = Model.get('party.party')
>>> customer = Party(name='Customer')
>>> customer.sale_shipment_cost_method = 'shipment'
>>> customer.save()
Create account category::
@@ -116,7 +117,8 @@ Sale products with cost on shipment::
>>> sale.carrier = carrier
>>> sale.payment_term = payment_term
>>> sale.invoice_method = 'shipment'
>>> sale.shipment_cost_method = 'shipment'
>>> sale.shipment_cost_method
'shipment'
>>> sale_line = sale.lines.new()
>>> sale_line.product = product
>>> sale_line.quantity = 5.0
+1
View File
@@ -14,6 +14,7 @@ extras_depend:
sale_promotion
sale_shipment_grouping
xml:
party.xml
sale.xml
stock.xml
message.xml
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/notebook/page[@id='sale']" position="inside">
<label name="sale_shipment_cost_method"/>
<field name="sale_shipment_cost_method"/>
</xpath>
</data>