Migrate 6.0

This commit refs #21782.
This commit is contained in:
José Antonio Díaz Miralles 2022-05-18 17:13:02 +02:00
parent ad49a33983
commit a970371c21
7 changed files with 72 additions and 33 deletions

View File

@ -6,6 +6,8 @@ from sql.conditionals import Coalesce
from sql.operators import Equal as SqlEqual
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.i18n import gettext
from trytond.exceptions import UserError
from genshi.template import TextTemplate
from io import open
import oyaml as yaml
@ -42,10 +44,13 @@ class EdocumentTemplate(ModelView, ModelSQL):
('document_party_exclude', Exclude(t,
(t.message_type, SqlEqual),
(Coalesce(t.party, -1), SqlEqual)),
'Combination of message type and party must be unique.')]
'edocument_edifact.msg_edi_party_message_type')]
def get_rec_name(self, name):
return self.message_type + ' ' + self.party.name
return ' '.join([
self.message_type,
self.party and self.party.name or ''
])
class EdocumentMessage(ModelView, ModelSQL):
@ -90,13 +95,13 @@ class EdocumentMessage(ModelView, ModelSQL):
class EdocumentMixin(object):
messages = fields.One2Many('edocument.message', 'origin', 'Message')
edocument_processed = fields.Function(
fields.Boolean('Processed'), 'get_edocument_processed',
searcher='search_edocument_processed')
edi_message = fields.Function(
fields.Char('EDI Code'), 'get_edi_message')
fields.Char('EDI Message'), 'get_edi_message')
def get_edocument_processed(self, name=None):
return len(self.messages) > 0
@ -239,22 +244,10 @@ class EdocumentExportMixin(object):
edi_file.write(file)
edi_file.close()
@classmethod
def __setup__(cls):
super(cls).__setup__()
cls._error_messages.update({
'company_unique': ('Cannot send invoices from more than '
'1 company.'),
'EDI_sender': 'Company %s lacks EDI sender identifier.',
'EDI_sequence':
'EDI Sequence must be defined in Edocument Configuration.',
'EDI_receiver': 'Party %s lacks EDI receiver identifier.',
'EDI_export_path':
'EDI export path is not defined in Edocument Configuration'})
def _edi_template(self, message_type, party):
pool = Pool()
EdocumentTemplate = pool.get('edocument.template')
templates = EdocumentTemplate.search([
('message_type', '=', message_type),
('party', '=', party)])
@ -269,9 +262,9 @@ class EdocumentExportMixin(object):
def generate_message(self, message_type, export_again=False):
pool = Pool()
_model_name = Transaction().context['active_model']
ActiveModel = pool.get(_model_name)
ActiveModel = self.model
Message = pool.get('edocument.message')
domain = [('id', 'in', Transaction().context['active_ids'])]
if not export_again:
domain.append(('edocument_processed', '=', False))
@ -280,18 +273,20 @@ class EdocumentExportMixin(object):
return None, None
companies = set(x.company for x in records)
if len(companies) > 1:
self.raise_user_error('company_unique')
raise UserError(gettext('edocument_edifact.msg_company_unique'))
company, = companies
edifact_sender = [x for x in company.party.identifiers
if x.type == 'EDI_sender']
if not edifact_sender:
self.raise_user_error('EDI_sender', company.party.name)
raise UserError(gettext('edocument_edifact.msg_EDI_sender',
company=company.party.name))
parties = set(x.party for x in records)
party, = parties
edifact_receiver = [x for x in party.identifiers
if x.type == 'EDI_receiver']
if not edifact_receiver:
self.raise_user_error('EDI_receiver', party.name)
raise UserError(gettext('edocument_edifact.msg_EDI_receiver',
party=party.name))
template, encoding = self._edi_template(message_type, party)
loader = TextTemplate(template)
for record in records:
@ -302,7 +297,7 @@ class EdocumentExportMixin(object):
"message": message,
"sender": edifact_sender[0].code,
"receiver": edifact_receiver[0].code,
"records": [[message.rec_name, record]],
"records": [[message.code, record]],
"date": message.create_date.strftime("%y%m%d"),
"time": message.create_date.strftime("%H%M")
}
@ -319,5 +314,5 @@ class EdocumentExportMixin(object):
file_name = os.path.join(conf.export_path, name)
self._write_file(file_name, message.message, encoding=encoding)
if not message.code:
self.raise_user_error('EDI_sequence')
raise UserError(gettext('edocument_edifact.msg_EDI_sequence'))
return message.message, message_type + message.code + '.EDI'

View File

@ -4,7 +4,6 @@
<tryton>
<data>
<record model="ir.sequence.type" id="sequence_type_edocument">
<field name="code">edocument</field>
<field name="name">Electronic Document</field>
</record>
<record model="ir.sequence.type-res.group"
@ -14,9 +13,9 @@
</record>
<record model="ir.sequence" id="sequence_edocument">
<field name="name">Electronic Document sequence</field>
<field name="code">edocument</field>
<field name="sequence_type" ref="sequence_type_edocument"/>
</record>
<!-- Edocument Template -->
<record model="ir.ui.view" id="edocument_template_view_tree">
<field name="model">edocument.template</field>

View File

@ -2,10 +2,30 @@
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "error:edocument.template:"
msgctxt "model:ir.message,text:msg_edi_party_message_type"
msgid "Combination of message type and party must be unique."
msgstr "La combinación de tipo de mensaje y tercero debe ser única."
msgctxt "model:ir.message,text:msg_company_unique"
msgid "Cannot send invoices from more than 1 company."
msgstr "No se pueden enviar facturas desde más de una empresa."
msgctxt "model:ir.message,text:msg_EDI_sender"
msgid "Company \"%(company)s\" lacks EDI sender identifier."
msgstr "La empresa \"%(company)s\" carece del identificador EDI de emisor."
msgctxt "model:ir.message,text:msg_EDI_sequence"
msgid "EDI Sequence must be defined in Edocument Configuration."
msgstr "Secuencia EDI debe definirse en Configuración de Documentación Electrónica."
msgctxt "model:ir.message,text:msg_EDI_receiver"
msgid "Party \"%(party)s\" lacks EDI receiver identifier."
msgstr "El tercero \"%(party)s\" carece del identificador EDI de receptor"
msgctxt "model:ir.message,text:msg_EDI_export_path"
msgid "EDI export path is not defined in Edocument Configuration."
msgstr "Ruta de exportación EDI no está definida en Configuración de Documentación Electrónica."
msgctxt "field:edocument.configuration,create_date:"
msgid "Create Date"
msgstr "Fecha de creación"

25
message.xml Normal file
View File

@ -0,0 +1,25 @@
<?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 grouped="1">
<record model="ir.message" id="msg_company_unique">
<field name="text">Cannot send invoices from more than 1 company.</field>
</record>
<record model="ir.message" id="msg_edi_party_message_type">
<field name="text">Combination of message type and party must be unique.</field>
</record>
<record model="ir.message" id="msg_EDI_sender">
<field name="text">Company "%(company)s" lacks EDI sender identifier.</field>
</record>
<record model="ir.message" id="msg_EDI_sequence">
<field name="text">EDI Sequence must be defined in Edocument Configuration.</field>
</record>
<record model="ir.message" id="msg_EDI_receiver">
<field name="text">Party "%(party)s" lacks EDI receiver identifier.</field>
</record>
<record model="ir.message" id="msg_EDI_export_path">
<field name="text">EDI export path is not defined in Edocument Configuration.</field>
</record>
</data>
</tryton>

View File

@ -35,12 +35,11 @@ class PartyIdentifier(metaclass=PoolMeta):
__name__ = 'party.identifier'
@classmethod
def __setup__(cls):
super(PartyIdentifier, cls).__setup__()
cls.type.selection.extend([
def get_types(cls):
return super().get_types() + [
('EDI_sender', 'EDI Sender'),
('EDI_receiver', 'EDI Receiver'),
('EDI_supplier', 'EDI Supplier'),
('EDI_payer', 'EDI Payer'),
('EDI_buyer', 'EDI Buyer'),
('EDI_invoice', 'EDI Invoice')])
('EDI_invoice', 'EDI Invoice')]

View File

@ -5,7 +5,7 @@
<data>
<record model="ir.ui.view" id="party_view_form">
<field name="model">party.party</field>
<field name="inherit" ref="party_edi.party_view_form"/>
<field name="inherit" ref="party.party_view_form"/>
<field name="name">party_form</field>
</record>
</data>

View File

@ -17,3 +17,4 @@ xml:
incoterm.xml
edocument.xml
party.xml
message.xml