Require incoterm on sale for EU countries if intratstat is extended
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
from trytond.pool import Pool
|
||||
|
||||
from . import (
|
||||
account, account_stock_eu, carrier, company, country, customs, stock)
|
||||
account, account_stock_eu, carrier, company, country, customs, sale, stock)
|
||||
|
||||
__all__ = ['register']
|
||||
|
||||
@@ -38,6 +38,10 @@ def register():
|
||||
stock.Move_Incoterm,
|
||||
module='account_stock_eu', type_='model',
|
||||
depends=['incoterm'])
|
||||
Pool.register(
|
||||
sale.Sale_Incoterm,
|
||||
module='account_stock_eu', type_='model',
|
||||
depends=['sale', 'incoterm'])
|
||||
Pool.register(
|
||||
stock.Move_Consignment,
|
||||
module='account_stock_eu', type_='model',
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# 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.modules.account.exceptions import FiscalYearNotFoundError
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
|
||||
|
||||
class Sale_Incoterm(metaclass=PoolMeta):
|
||||
__name__ = 'sale.sale'
|
||||
|
||||
@property
|
||||
@fields.depends('company')
|
||||
def _incoterm_required(self):
|
||||
pool = Pool()
|
||||
FiscalYear = pool.get('account.fiscalyear')
|
||||
|
||||
required = super()._incoterm_required
|
||||
|
||||
if not required and self.company and self.company.incoterms:
|
||||
if (self.warehouse and self.warehouse.address
|
||||
and self.shipment_address):
|
||||
try:
|
||||
fiscalyear = FiscalYear.find(
|
||||
self.company.id,
|
||||
date=self.sale_date)
|
||||
except FiscalYearNotFoundError:
|
||||
pass
|
||||
else:
|
||||
if fiscalyear.intrastat_extended:
|
||||
from_country = self.warehouse.address.country
|
||||
if from_country:
|
||||
from_europe = from_country.is_member(
|
||||
'country.organization_eu',
|
||||
self.sale_date)
|
||||
else:
|
||||
from_europe = None
|
||||
to_country = self.shipment_address.country
|
||||
if to_country:
|
||||
to_europe = to_country.is_member(
|
||||
'country.organization_eu',
|
||||
self.sale_date)
|
||||
else:
|
||||
to_europe = None
|
||||
required = (
|
||||
(from_country != to_country)
|
||||
and not (from_europe and to_europe))
|
||||
return required
|
||||
Reference in New Issue
Block a user