Add a default Incoterm to web shops

The default Incoterm is set by default to sale from web shop for which it is
required.
And the shipment address is also set by default as Incoterm location when it is
required.

Closes #14337
This commit is contained in:
Cédric Krier
2025-10-31 11:57:19 +01:00
parent 62a54d655f
commit 59184cdfdd
8 changed files with 90 additions and 2 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add a default Incoterm to web shops
* Allow modifications of incoterm until customer's shipments has been shipped
Version 7.6.0 - 2025-04-28
+26 -1
View File
@@ -2,7 +2,7 @@
# this repository contains the full copyright notices and license terms.
from trytond.i18n import gettext
from trytond.model import fields
from trytond.model import ModelView, Workflow, fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
@@ -105,6 +105,31 @@ class Sale_Carrier(metaclass=PoolMeta):
self._set_default_incoterm()
class Sale_WebShop(metaclass=PoolMeta):
__name__ = 'sale.sale'
@property
@fields.depends('web_shop')
def _party_incoterms(self):
incoterms = super()._party_incoterms
if self.web_shop:
incoterms = []
return incoterms
@classmethod
@ModelView.button
@Workflow.transition('quotation')
def quote(cls, sales):
for sale in sales:
if sale.web_shop and sale._incoterm_required:
if not sale.incoterm:
sale.incoterm = sale.web_shop.default_incoterm
if sale.incoterm and sale.incoterm.location:
sale.incoterm_location = sale.shipment_address
cls.save(sales)
super().quote(sales)
class Opportunity(IncotermMixin, metaclass=PoolMeta):
__name__ = 'sale.opportunity'
+1
View File
@@ -63,6 +63,7 @@ tests_require = [
get_require_version('trytond_sale_opportunity'),
get_require_version('trytond_sale_shipment_grouping'),
get_require_version('trytond_stock'),
get_require_version('trytond_web_shop'),
]
setup(name=name,
+1 -1
View File
@@ -15,7 +15,7 @@ class IncotermTestCase(CompanyTestMixin, ModuleTestCase):
'carrier', 'company', 'purchase', 'purchase_request_quotation',
'sale', 'sale_shipment_cost', 'sale_opportunity',
'sale_shipment_grouping', 'stock', 'account_invoice',
'account_invoice_stock']
'account_invoice_stock', 'web_shop']
@with_transaction()
def test_shipment_grouping(self):
+7
View File
@@ -17,6 +17,7 @@ extras_depend:
sale_shipment_grouping
stock
stock_package_shipping
web_shop
xml:
incoterm.xml
company.xml
@@ -25,6 +26,7 @@ xml:
purchase.xml
sale.xml
stock.xml
web.xml
message.xml
[register]
@@ -75,3 +77,8 @@ model:
stock.ShipmentInReturn
stock.ShipmentOut
stock.ShipmentOutReturn
[register web_shop]
model:
sale.Sale_WebShop
web.Shop
+10
View File
@@ -0,0 +1,10 @@
<?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="//field[@name='guest_party']" position="after">
<newline/>
<label name="default_incoterm"/>
<field name="default_incoterm"/>
</xpath>
</data>
+32
View File
@@ -0,0 +1,32 @@
# 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 Pool, PoolMeta
from trytond.pyson import Eval
class Shop(metaclass=PoolMeta):
__name__ = 'web.shop'
default_incoterm = fields.Many2One(
'incoterm.incoterm', "Default Incoterm",
domain=[
('carrier', '=', 'seller'),
('id', 'in', Eval('available_incoterms', [])),
],
help="Used to fill incoterm on sales that require it.")
available_incoterms = fields.Function(fields.Many2Many(
'incoterm.incoterm', None, None, "Available Incoterms"),
'on_change_with_available_incoterms')
@fields.depends('company', methods=['_get_incoterm_pattern'])
def on_change_with_available_incoterms(self, name=None):
pool = Pool()
Incoterm = pool.get('incoterm.incoterm')
pattern = self._get_incoterm_pattern()
return Incoterm.get_incoterms(self.company, pattern)
@fields.depends()
def _get_incoterm_pattern(self):
return {}
+12
View File
@@ -0,0 +1,12 @@
<?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 depends="web_shop">
<record model="ir.ui.view" id="web_shop_view_form">
<field name="model">web.shop</field>
<field name="inherit" ref="web_shop.shop_view_form"/>
<field name="name">web_shop_form</field>
</record>
</data>
</tryton>