diff --git a/CHANGELOG b/CHANGELOG
index c5ba34da79..9b2c2a57ae 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Define default shipment cost method by party
* Add cost method to shipment
Version 6.0.0 - 2021-05-03
diff --git a/__init__.py b/__init__.py
index d69059be1c..9e169b0ba7 100644
--- a/__init__.py
+++ b/__init__.py
@@ -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,
diff --git a/party.py b/party.py
new file mode 100644
index 0000000000..df14ceca1d
--- /dev/null
+++ b/party.py
@@ -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 --git a/party.xml b/party.xml
new file mode 100644
index 0000000000..3e17f554da
--- /dev/null
+++ b/party.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+ party.party
+
+ party_form
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sale.py b/sale.py
index 8833254594..5edd63fa27 100644
--- a/sale.py
+++ b/sale.py
@@ -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):
diff --git a/tests/scenario_sale_shipment_cost.rst b/tests/scenario_sale_shipment_cost.rst
index 673e5ac9ee..9e5343bec2 100644
--- a/tests/scenario_sale_shipment_cost.rst
+++ b/tests/scenario_sale_shipment_cost.rst
@@ -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
diff --git a/tryton.cfg b/tryton.cfg
index 688a56ecbb..359ebd5e40 100644
--- a/tryton.cfg
+++ b/tryton.cfg
@@ -14,6 +14,7 @@ extras_depend:
sale_promotion
sale_shipment_grouping
xml:
+ party.xml
sale.xml
stock.xml
message.xml
diff --git a/view/party_form.xml b/view/party_form.xml
new file mode 100644
index 0000000000..5f3317a00a
--- /dev/null
+++ b/view/party_form.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+