changeset d7437e620941 in modules/sale_shipment_cost:default
details:
https://hg.tryton.org/modules/sale_shipment_cost?cmd=changeset&node=d7437e620941
description:
Define default shipment cost method by party
issue10160
review316991002
diffstat:
CHANGELOG | 1 +
__init__.py | 4 +++
party.py | 45 +++++++++++++++++++++++++++++++++++
party.xml | 24 ++++++++++++++++++
sale.py | 4 +++
tests/scenario_sale_shipment_cost.rst | 4 ++-
tryton.cfg | 1 +
view/party_form.xml | 9 +++++++
8 files changed, 91 insertions(+), 1 deletions(-)
diffs (165 lines):
diff -r 0680360327f9 -r d7437e620941 CHANGELOG
--- a/CHANGELOG Mon Oct 11 18:47:59 2021 +0200
+++ b/CHANGELOG Mon Oct 11 22:41:31 2021 +0200
@@ -1,3 +1,4 @@
+* Define default shipment cost method by party
* Add cost method to shipment
Version 6.0.0 - 2021-05-03
diff -r 0680360327f9 -r d7437e620941 __init__.py
--- a/__init__.py Mon Oct 11 18:47:59 2021 +0200
+++ b/__init__.py Mon Oct 11 22:41:31 2021 +0200
@@ -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 @@
def register():
Pool.register(
+ party.Party,
+ party.PartySaleMethod,
account.InvoiceLine,
sale.Configuration,
sale.ConfigurationSaleMethod,
diff -r 0680360327f9 -r d7437e620941 party.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/party.py Mon Oct 11 22:41:31 2021 +0200
@@ -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')
diff -r 0680360327f9 -r d7437e620941 party.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/party.xml Mon Oct 11 22:41:31 2021 +0200
@@ -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>
diff -r 0680360327f9 -r d7437e620941 sale.py
--- a/sale.py Mon Oct 11 18:47:59 2021 +0200
+++ b/sale.py Mon Oct 11 22:41:31 2021 +0200
@@ -153,6 +153,10 @@
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):
diff -r 0680360327f9 -r d7437e620941 tests/scenario_sale_shipment_cost.rst
--- a/tests/scenario_sale_shipment_cost.rst Mon Oct 11 18:47:59 2021 +0200
+++ b/tests/scenario_sale_shipment_cost.rst Mon Oct 11 22:41:31 2021 +0200
@@ -47,6 +47,7 @@
>>> 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.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
diff -r 0680360327f9 -r d7437e620941 tryton.cfg
--- a/tryton.cfg Mon Oct 11 18:47:59 2021 +0200
+++ b/tryton.cfg Mon Oct 11 22:41:31 2021 +0200
@@ -14,6 +14,7 @@
sale_promotion
sale_shipment_grouping
xml:
+ party.xml
sale.xml
stock.xml
message.xml
diff -r 0680360327f9 -r d7437e620941 view/party_form.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/view/party_form.xml Mon Oct 11 22:41:31 2021 +0200
@@ -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>