Carrier for shipment party, allow in the configuration of the sale to define that the carrier loaded in the sale is the carrier of shipment party

Task 037851
This commit is contained in:
Marina Nicolau 2019-06-18 15:52:01 +02:00
parent 57ba01762e
commit 1f0a7dbeed
10 changed files with 180 additions and 9 deletions

View File

@ -2,6 +2,7 @@
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.pool import Pool
from . import configuration
from . import invoice
from . import sale
from . import party
@ -9,6 +10,8 @@ from . import party
def register():
Pool.register(
invoice.Invoice,
configuration.Configuration,
configuration.ConfigurationCarrier,
sale.Sale,
party.Party,
module='sale_invoice_grouping_shipment_party', type_='model')

35
configuration.py Normal file
View File

@ -0,0 +1,35 @@
# 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, ModelSQL
from trytond.pool import Pool, PoolMeta
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
__all__ = ['Configuration', 'ConfigurationCarrier']
sale_default_party_carrier = fields.Selection([
(None, 'Party (default)'),
('shipment_party', 'Shipment Party'),
], 'Default Party Carrier')
class Configuration(metaclass=PoolMeta):
__name__ = 'sale.configuration'
sale_default_party_carrier = fields.MultiValue(sale_default_party_carrier)
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field == 'sale_default_party_carrier':
return pool.get('sale.configuration.sale_carrier')
return super(Configuration, cls).multivalue_model(field)
@classmethod
def default_sale_party_carrier(cls, **pattern):
return cls.multivalue_model(
'sale_default_party_carrier').default_sale_party_carrier()
class ConfigurationCarrier(metaclass=PoolMeta):
__name__ = 'sale.configuration.sale_carrier'
sale_default_party_carrier = sale_default_party_carrier

13
configuration.xml Normal file
View File

@ -0,0 +1,13 @@
<?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>
<!-- configuration -->
<record model="ir.ui.view" id="sale_configuration_view_form">
<field name="model">sale.configuration</field>
<field name="inherit" ref="sale.sale_configuration_view_form"/>
<field name="name">configuration_form</field>
</record>
</data>
</tryton>

View File

@ -6,8 +6,45 @@ msgctxt "field:account.invoice,shipment_party:"
msgid "Shipment Party"
msgstr "Tercer de l'enviament"
msgctxt "model:ir.message,text:msg_error_party_payer"
msgid "Party \"%(name)s\" cannot be used as a payer because it has a payer defined"
msgctxt "field:party.party,party_sale_payer:"
msgid "Party Sale Payer"
msgstr "Tercer pagador"
msgctxt "field:sale.configuration,sale_default_party_carrier:"
msgid "Default Party Carrier"
msgstr "Transportista del tercer per defecte"
msgctxt "field:sale.configuration.sale_carrier,sale_default_party_carrier:"
msgid "Default Party Carrier"
msgstr "Transportista del tercer per defecte"
msgctxt "help:party.party,party_sale_payer:"
msgid ""
"Default party payer when selecting a shipment party on sales or invoices."
msgstr ""
"El tercer \"%(name)s\" no pot utilitzar-se com a pagador, perquè ja en té un de "
"definit"
"Pagador per defecte quan es selecciona un tercer a enviar en la venda."
msgctxt "model:ir.message,text:msg_error_party_payer"
msgid ""
"Party \"%(name)s\" cannot be used as a payer because it has a payer defined"
msgstr ""
"El tercer \"%(name)s\" no pot utilitzar-se com a pagador, perquè ja en té un"
" de definit"
msgctxt "selection:sale.configuration,sale_default_party_carrier:"
msgid "Party (default)"
msgstr "Tercer (per defecte)"
msgctxt "selection:sale.configuration,sale_default_party_carrier:"
msgid "Shipment Party"
msgstr "Tercer de l'enviament"
msgctxt ""
"selection:sale.configuration.sale_carrier,sale_default_party_carrier:"
msgid "Party (default)"
msgstr "Tercer (per defecte)"
msgctxt ""
"selection:sale.configuration.sale_carrier,sale_default_party_carrier:"
msgid "Shipment Party"
msgstr "Tercer de l'enviament"

View File

@ -6,8 +6,45 @@ msgctxt "field:account.invoice,shipment_party:"
msgid "Shipment Party"
msgstr "Tercero del envío"
msgctxt "model:ir.message,text:msg_error_party_payer"
msgid "Party \"%(name)s\" cannot be used as a payer because it has a payer defined"
msgctxt "field:party.party,party_sale_payer:"
msgid "Party Sale Payer"
msgstr "Tercero pagador"
msgctxt "field:sale.configuration,sale_default_party_carrier:"
msgid "Default Party Carrier"
msgstr "Transportista del tercero por defecto"
msgctxt "field:sale.configuration.sale_carrier,sale_default_party_carrier:"
msgid "Default Party Carrier"
msgstr "Transportista del tercero por defecto"
msgctxt "help:party.party,party_sale_payer:"
msgid ""
"Default party payer when selecting a shipment party on sales or invoices."
msgstr ""
"El tercero \"%(name)s\" no se puede utilizar como pagador porque ya tiene uno "
"definido"
"Pagador por defecto cuando seleccionamos un tercero a enviar en la venta."
msgctxt "model:ir.message,text:msg_error_party_payer"
msgid ""
"Party \"%(name)s\" cannot be used as a payer because it has a payer defined"
msgstr ""
"El tercero \"%(name)s\" no se puede utilizar como pagador porque ya tiene "
"uno definido"
msgctxt "selection:sale.configuration,sale_default_party_carrier:"
msgid "Party (default)"
msgstr "Tercero (per defecto)"
msgctxt "selection:sale.configuration,sale_default_party_carrier:"
msgid "Shipment Party"
msgstr "Tercero del envío"
msgctxt ""
"selection:sale.configuration.sale_carrier,sale_default_party_carrier:"
msgid "Party (default)"
msgstr "Tercero (per defecto)"
msgctxt ""
"selection:sale.configuration.sale_carrier,sale_default_party_carrier:"
msgid "Shipment Party"
msgstr "Tercero del envío"

12
party.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!-- 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>
</data>
</tryton>

15
sale.py
View File

@ -1,6 +1,7 @@
# 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.pool import PoolMeta
from trytond.pool import PoolMeta, Pool
from trytond.model import fields
from trytond.i18n import gettext
from trytond.exceptions import UserError
@ -53,3 +54,15 @@ class Sale(metaclass=PoolMeta):
else:
self.party = self.shipment_party
self.on_change_party()
@fields.depends('carrier')
def on_change_party(self):
super(Sale, self).on_change_party()
Config = Pool().get('sale.configuration')
config = Config(1)
if config:
config = config.sale_default_party_carrier
if config == 'shipment_party' and self.shipment_party:
if self.shipment_party.carrier:
self.carrier = self.shipment_party.carrier

View File

@ -2,11 +2,14 @@
version=5.3.0
depends:
ir
sale_carrier
sale_invoice_grouping
extras_depend:
account_invoice_discount_global
sale_invoice_grouping_by_address
xml:
configuration.xml
invoice.xml
party.xml
sale.xml
message.xml

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/field[@name='sale_carrier']" position="after">
<label name="sale_default_party_carrier"/>
<field name="sale_default_party_carrier"/>
</xpath>
</data>

9
view/party_form.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license types. -->
<data>
<xpath expr="/form/notebook/page[@id='sale']/field[@name='sale_price_list']" position="after">
<label name="party_sale_payer"/>
<field name="party_sale_payer"/>
</xpath>
</data>