From ea853a293030da3db68337b731fe97d7bda8d702 Mon Sep 17 00:00:00 2001 From: Marcos Sabater Date: Wed, 28 Aug 2019 16:37:06 +0200 Subject: [PATCH] added template per party --- __init__.py | 5 +- configuration.py | 43 ++++++++++++++++ edocument.py | 33 ++++++++++-- edocument.xml | 86 ++++++++++++++++++++++++++++++++ party.py | 10 ++-- setup.py | 20 +++++++- view/configuration_form.xml | 14 +++--- view/edocument_template_form.xml | 11 ++++ view/edocument_template_tree.xml | 7 +++ 9 files changed, 210 insertions(+), 19 deletions(-) create mode 100644 configuration.py create mode 100644 view/edocument_template_form.xml create mode 100644 view/edocument_template_tree.xml diff --git a/__init__.py b/__init__.py index 8cf47fb..ac701b4 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,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 edocument from . import stock from . import party @@ -10,11 +11,13 @@ from . import incoterm def register(): Pool.register( + configuration.Configuration, + configuration.ConfigurationSequence, edocument.EdocumentMessage, + edocument.EdocumentTemplate, party.Party, party.PartyIdentifier, stock.Configuration, - stock.ConfigurationSequence, stock.ConfigurationEDIOutputPath, stock.UnitLoad, incoterm.Rule, diff --git a/configuration.py b/configuration.py new file mode 100644 index 0000000..7deabe3 --- /dev/null +++ b/configuration.py @@ -0,0 +1,43 @@ +# The COPYRIGHT file at the top level of this repository contains the full +# copyright notices and license terms. +from trytond.model import ModelSQL, ModelSingleton, ModelView, fields +from trytond.pool import Pool +from trytond.modules.company.model import ( + CompanyMultiValueMixin, CompanyValueMixin) + +__all__ = ['Configuration', 'ConfigurationSequence'] + + +class Configuration( + ModelSingleton, ModelSQL, ModelView, CompanyMultiValueMixin): + """Edocument Configuration""" + __name__ = 'edocument.configuration' + + edocument_sequence = fields.MultiValue( + fields.Many2One('ir.sequence', 'Electronic Document Sequence', + required=True)) + export_path = fields.Char('Export Path') + + @classmethod + def multivalue_model(cls, field): + pool = Pool() + if field == 'edocument_sequence': + return pool.get('edocument.configuration.sequence') + return super(Configuration, cls).multivalue_model(field) + + +class ConfigurationSequence(ModelSQL, CompanyValueMixin): + """Edocument Configuration Sequence""" + __name__ = 'edocument.configuration.sequence' + + edocument_sequence = fields.Many2One( + 'ir.sequence', 'Electronic Document Sequence', required=True) + + @classmethod + def default_edocument_sequence(cls): + pool = Pool() + ModelData = pool.get('ir.model.data') + try: + return ModelData.get_id('edocument_edifact', 'sequence_edocument') + except KeyError: + return None diff --git a/edocument.py b/edocument.py index 07932b4..0581082 100644 --- a/edocument.py +++ b/edocument.py @@ -1,16 +1,43 @@ # The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond.model import ModelSQL, ModelView, fields +from trytond.model import ModelSQL, ModelView, fields, Exclude +from sql.conditionals import Coalesce +from sql.operators import Equal as SqlEqual from trytond.pool import Pool from io import open import oyaml as yaml import os -__all__ = ['EdocumentMessage'] +__all__ = ['EdocumentMessage', 'EdocumentTemplate'] KNOWN_EXTENSIONS = ['.txt', '.edi', '.pla'] +class EdocumentTemplate(ModelView, ModelSQL): + """Electronic Document Template""" + __name__ = 'edocument.template' + rec_name = fields.Function(fields.Char('Record Name'), 'get_rec_name') + + message_type = fields.Selection([('DESADV', 'DESADV'), + ('INVOIC', 'INVOIC')], 'Document', required=True) + party = fields.Many2One('party.party', 'Party') + template = fields.Text('Template') + + @classmethod + def __setup__(cls): + super(EdocumentTemplate, cls).__setup__() + + t = cls.__table__() + cls._sql_constraints = [ + ('document_party_exclude', Exclude(t, + (t.message_type, SqlEqual), + (Coalesce(t.party, -1), SqlEqual)), + 'Combination of message type and party must be unique.')] + + def get_rec_name(self, name): + return self.message_type + ' ' + self.party.name + + class EdocumentMessage(ModelView, ModelSQL): """EDIFACT message""" __name__ = 'edocument.message' @@ -23,7 +50,7 @@ class EdocumentMessage(ModelView, ModelSQL): @classmethod def create(cls, vlist): pool = Pool() - Configuration = pool.get('stock.configuration') + Configuration = pool.get('edocument.configuration') Sequence = Pool().get('ir.sequence') config = Configuration(1) diff --git a/edocument.xml b/edocument.xml index dda493f..f40d0fc 100644 --- a/edocument.xml +++ b/edocument.xml @@ -16,5 +16,91 @@ Electronic Document sequence edocument.message + + + + edocument.template + tree + edocument_template_tree + + + + edocument.template + form + edocument_template_form + + + + Edocument Templates + edocument.template + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + edocument.configuration + form + configuration_form + + + + Edocument Configuration + edocument.configuration + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/party.py b/party.py index 77afe06..c974d88 100644 --- a/party.py +++ b/party.py @@ -9,11 +9,11 @@ __all__ = ['Party', 'PartyIdentifier'] class Party(metaclass=PoolMeta): __name__ = 'party.party' - edi_template_path = fields.Char('Template Path') edi_add_header = fields.Boolean('Add Header') edi_release_number = fields.Selection([ (None, ' '), ('96A', '96A'), + ('93A', '93A'), ('01B', '01B'), ], 'Release Number') edi_assigned_code = fields.Selection([ @@ -37,8 +37,8 @@ class PartyIdentifier(metaclass=PoolMeta): @classmethod def __setup__(cls): super(PartyIdentifier, cls).__setup__() - cls.type.selection.extend( - [('EDI_sender', 'EDI Sender'), + cls.type.selection.extend([ + ('EDI_sender', 'EDI Sender'), ('EDI_receiver', 'EDI Receiver'), - ('EDI_supplier', 'EDI Supplier')]) - + ('EDI_supplier', 'EDI Supplier'), + ('EDI_payer', 'EDI Payer')]) diff --git a/setup.py b/setup.py index 84b1fce..d99a64f 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,9 @@ from configparser import ConfigParser MODULE2PREFIX = { 'incoterm': 'datalife', 'stock_unit_load': 'datalife', - 'product_ean': 'datalife' + 'product_ean': 'datalife', + 'product_cross_reference': 'datalife', + 'party_edi': 'nantic' } @@ -34,7 +36,7 @@ def get_require_version(name): config = ConfigParser() -config.readfp(open('tryton.cfg')) +config.read_file(open('tryton.cfg')) info = dict(config.items('tryton')) for key in ('depends', 'extras_depend', 'xml'): if key in info: @@ -73,6 +75,20 @@ dependency_links = { 'branch': branch, 'series': series, }, + 'product_cross_reference': + 'hg+https://bitbucket.org/datalife_sco/' + 'trytond-product_cross_reference@%(branch)s' + '#egg=datalife_product_cross_reference-%(series)s' % { + 'branch': branch, + 'series': series, + }, + 'party_edi': + 'hg+https://bitbucket.org/nantic/' + 'trytond-party_edi@%(branch)s' + '#egg=nantic_party_edi-%(series)s' % { + 'branch': branch, + 'series': series, + }, } requires = [] diff --git a/view/configuration_form.xml b/view/configuration_form.xml index 9ad0112..77d65dd 100644 --- a/view/configuration_form.xml +++ b/view/configuration_form.xml @@ -1,11 +1,9 @@ - - - - \ No newline at end of file +
+