1
0
Fork 0
mirror of synced 2023-12-14 06:03:13 +01:00

Add the possibility to choose send or not the EDI file automatically.

Add an advice when send the EDI file automatically.
This commit is contained in:
Bernat Brunet 2021-11-18 15:39:19 +01:00
parent f193522c21
commit d206a19dce
12 changed files with 152 additions and 95 deletions

View file

@ -3,12 +3,12 @@
from trytond.pool import Pool
from . import invoice
from . import sale
from . import configuration
def register():
Pool.register(
invoice.Cron,
invoice.InvoiceEdiConfiguration,
invoice.InvoiceEdi,
invoice.InvoiceEdiLine,
invoice.SupplierEdi,
@ -19,6 +19,7 @@ def register():
invoice.InvoiceEdiTax,
invoice.Invoice,
invoice.InvoiceLine,
configuration.InvoiceEdiConfiguration,
module='account_invoice_edi', type_='model')
Pool.register(
sale.Sale,

22
configuration.py Normal file
View file

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.model import fields, ModelSQL, ModelView, ModelSingleton
class InvoiceEdiConfiguration(ModelSingleton, ModelSQL, ModelView):
'Invoice Edi Configuration'
__name__ = 'invoice.edi.configuration'
edi_files_path = fields.Char('EDI Invoice Inbox Path')
outbox_path_edi = fields.Char('EDI Invoice Outbox Path')
separator = fields.Char('Separator')
automatic_edi_invoice_out = fields.Boolean('Send EDI file automatically')
@classmethod
def default_separator(cls):
return '|'
@classmethod
def default_automatic_edi_invoice_out(cls):
return True

48
configuration.xml Normal file
View file

@ -0,0 +1,48 @@
<?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="configuration_view_form">
<field name="model">invoice.edi.configuration</field>
<field name="type">form</field>
<field name="name">configuration_form</field>
</record>
<record model="ir.action.act_window"
id="act_configuration_form">
<field name="name">EDI Invoice Configuration</field>
<field name="res_model">invoice.edi.configuration</field>
</record>
<record model="ir.action.act_window.view"
id="act_configuration_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="configuration_view_form"/>
<field name="act_window" ref="act_configuration_form"/>
</record>
<menuitem parent="account_invoice_edi.menu_edi_invoices"
action="act_configuration_form"
id="menuitem_account_configuration"
sequence="0" icon="tryton-list"/>
<record model="ir.model.access" id="access_invoice_edi_configuration">
<field name="model"
search="[('model', '=', 'invoice.edi.configuration')]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access"
id="access_invoice_edi_configuration_account_admin">
<field name="model"
search="[('model', '=', 'invoice.edi.configuration')]"/>
<field name="group" ref="account.group_account_admin"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
</data>
</tryton>

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.model import fields, ModelSQL, ModelView, ModelSingleton
from trytond.model import fields, ModelSQL, ModelView
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, Not
from trytond.transaction import Transaction
@ -15,9 +15,9 @@ import codecs
from stdnum import ean
from jinja2 import Template
__all__ = ['InvoiceEdiConfiguration', 'InvoiceEdi', 'InvoiceEdiLine',
'SupplierEdi', 'InvoiceEdiReference', 'InvoiceEdiMaturityDates',
'InvoiceEdiDiscount', 'InvoiceEdiLineQty', 'InvoiceEdiTax', 'Cron']
__all__ = ['InvoiceEdi', 'InvoiceEdiLine', 'SupplierEdi',
'InvoiceEdiReference', 'InvoiceEdiMaturityDates', 'InvoiceEdiDiscount',
'InvoiceEdiLineQty', 'InvoiceEdiTax', 'Cron']
DEFAULT_FILES_LOCATION = '/tmp/invoice'
@ -50,19 +50,6 @@ class Cron(metaclass=PoolMeta):
])
class InvoiceEdiConfiguration(ModelSingleton, ModelSQL, ModelView):
'Invoice Edi Configuration'
__name__ = 'invoice.edi.configuration'
edi_files_path = fields.Char('EDI Invoice Inbox Path')
outbox_path_edi = fields.Char('EDI Invoice Outbox Path')
separator = fields.Char('Separator')
@classmethod
def default_separator(cls):
return '|'
SUPPLIER_TYPE = [('NADSCO', 'Legal Supplier'),
('NADBCO', 'Legal Purchaser'), ('NADSU', 'Supplier'),
('NADBY', 'Purchaser'), ('NADII', 'Invoice Issuer'),
@ -1020,12 +1007,13 @@ class Invoice(metaclass=PoolMeta):
@classmethod
def __setup__(cls):
super(Invoice, cls).__setup__()
cls._check_modify_exclude += {'is_edi'}
cls._buttons.update({
'generate_edi_file': {'invisible': (
Not(Eval('is_edi')) |
(Eval('type') != 'out') |
Not(Eval('state').in_(['posted', 'paid']))
)
},
)},
})
@classmethod
@ -1041,8 +1029,24 @@ class Invoice(metaclass=PoolMeta):
@classmethod
@ModelView.button
def generate_edi_file(cls, invoices):
pool = Pool()
Configuration = pool.get('invoice.edi.configuration')
Warning = pool.get('res.user.warning')
post_edi_invoice = Transaction().context.get('post_edi_invoice', False)
if post_edi_invoice:
configuration = Configuration(1)
if not configuration.automatic_edi_invoice_out:
return
for invoice in invoices:
if invoice.is_edi:
if invoice.type == 'out' and invoice.is_edi:
if post_edi_invoice:
warning_name = '%s.send_edi_invoice' % invoice
if Warning.check(warning_name):
raise UserWarning(warning_name, gettext(
'account_invoice_edi.msg_send_edi_invoice',
invoice=invoice.number))
invoice.generate_edi()
def generate_edi(self):
@ -1071,6 +1075,7 @@ class Invoice(metaclass=PoolMeta):
Warning = pool.get('res.user.warning')
super(Invoice, cls).post(invoices)
differences = []
for invoice in invoices:
if invoice.type == 'out' or not invoice.is_edi:
@ -1088,17 +1093,31 @@ class Invoice(metaclass=PoolMeta):
raise UserWarning(key, gettext(
'account_invoice_edi.confirm_invoice_with_difference',
invoices=",".join([x.reference for x in differences])))
cls.generate_edi_file(invoices)
with Transaction().set_context(post_edi_invoice=True):
cls.generate_edi_file(invoices)
class InvoiceLine(metaclass=PoolMeta):
__name__ = 'account.invoice.line'
shipment_reference = fields.Function(fields.Char('Shipment Number'),
'get_shipment_reference')
code_ean13 = fields.Function(fields.Char("Code EAN13"), 'get_code_ean13')
def get_code_ean13(self):
def get_code_ean13(self, name):
if self.product:
for identifier in self.product.identifiers:
if identifier.type == 'ean' and len(identifier.code) == 13:
return identifier.code
return None
def get_shipment_reference(self, name):
name = name[9:]
values = []
for move in self.stock_moves:
value = getattr(move.shipment, name, None)
if value:
values.append(value)
if values:
return " / ".join(values)
return ""

View file

@ -6,48 +6,6 @@
<menuitem name="EDI Invoices" parent="account.menu_account"
id="menu_edi_invoices" sequence="40"/>
<record model="ir.ui.view" id="configuration_view_form">
<field name="model">invoice.edi.configuration</field>
<field name="type">form</field>
<field name="name">configuration_form</field>
</record>
<record model="ir.action.act_window"
id="act_configuration_form">
<field name="name">EDI Invoice Configuration</field>
<field name="res_model">invoice.edi.configuration</field>
</record>
<record model="ir.action.act_window.view"
id="act_configuration_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="configuration_view_form"/>
<field name="act_window" ref="act_configuration_form"/>
</record>
<menuitem parent="menu_edi_invoices"
action="act_configuration_form"
id="menuitem_account_configuration"
sequence="0" icon="tryton-list"/>
<record model="ir.model.access" id="access_invoice_edi_configuration">
<field name="model"
search="[('model', '=', 'invoice.edi.configuration')]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access"
id="access_invoice_edi_configuration_account_admin">
<field name="model"
search="[('model', '=', 'invoice.edi.configuration')]"/>
<field name="group" ref="account.group_account_admin"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.ui.view" id="supplier_edi_view_form">
<field name="model">invoice.edi.supplier</field>
<field name="type">form</field>
@ -213,12 +171,4 @@
<field name="group" ref="account.group_account"/>
</record>
</data>
<data depends="sale_edi">
<!-- sale -->
<record model="ir.ui.view" id="sale_edi_invoice_configuration_view_form">
<field name="model">invoice.edi.configuration</field>
<field name="inherit" ref="configuration_view_form"/>
<field name="name">sale_edi_invoice_configuration_form</field>
</record>
</data>
</tryton>

View file

@ -3,10 +3,10 @@ INV|{{invoice.number}}|380
DTM|{{invoice.invoice_date|replace('-','')}}
PAI|14E
{% for sale in invoice.sales -%}
RFF|ON|{{sale.number}}
RFF|ON|{{sale.reference}}
{% endfor -%}
{% for shipment in invoice.shipments -%}
RFF|DQ|{{shipment.number}}
RFF|DQ|{{shipment.reference}}
{% endfor -%}
NADBCO|{{invoice.party.edi_operational_point}}|{{invoice.party.name}}|{{invoice.party.addresses[0].street|replace('\n', '')}}|{{invoice.party.addresses[0].city}}|{{invoice.party.addresses[0].zip}}|{{invoice.party.identifier_code}}
NADSU|{{invoice.company.party.edi_operational_point}}|{{invoice.company.party.name}}|registre_mercantil|{{invoice.company.party.addresses[0].street|replace('\n', '')}}|{{invoice.company.party.addresses[0].city}}|{{invoice.company.party.addresses[0].zip}}|{{invoice.company.party.identifier_code}}
@ -14,7 +14,7 @@ NADBY|{{invoice.party.edi_operational_point}}|{{invoice.party.name}}|{{invoice.p
NADII|{{invoice.company.party.edi_operational_point}}|{{invoice.company.party.name}}
NADIV|{{invoice.party.edi_operational_point}}|{{invoice.party.name}}|{{invoice.party.addresses[0].street|replace('\n', '')}}|{{invoice.party.addresses[0].city}}|{{invoice.party.addresses[0].zip}}|{{invoice.party.identifier_code}}
NADPR|{{invoice.party.edi_operational_point}}|{{invoice.party.name}}|{{invoice.party.addresses[0].street|replace('\n',
'')}}|{{invoice.party.addresses[0].city}}|{{invoice.party.addresses[0].zip}}|{{invoice.party.addresses[0].counrty.code}}|{{invoice.party.identifier_code}}
'')}}|{{invoice.party.addresses[0].city}}|{{invoice.party.addresses[0].zip}}|{{invoice.party.addresses[0].country.code}}|{{invoice.party.identifier_code}}
NADPE|{{invoice.company.party.edi_operational_point}}|{{invoice.company.party.name}}
CUX|EUR|4
PAT|35|{{invoice.invoice_date|replace('-','')}}|{{invoice.total_amount}}
@ -27,8 +27,8 @@ MOALIN|{{line.amount}}
PRILIN|AAA|0
PRILIN|AAB|{{line.unit_price}}
{% if invoice.shipments|length > 1 -%}
RFFLIN|ON|{{line.sale.number}}
RFFLIN|DQ|{{line.shipment_number}}
RFFLIN|ON|{{line.sale.reference}}
RFFLIN|DQ|{{line.shipment_reference}}
{% endif -%}
{% if line.discount -%}
ALCLIN|A|1|TD|{{(line.discount * 100)}}
@ -37,7 +37,7 @@ ALCLIN|A|1|TD|{{(line.discount * 100)}}
TAXLIN|VAT|{{(tax.rate * 100)|int}}|{{(line.amount * tax.rate)|round(2)}}
{% endfor -%}
{% endfor -%}
CNTRES|2|{{ count(invoice.lines) }}
CNTRES|2|{{ invoice.lines|length }}
MOARES|||{{ invoice.untaxed_amount }}|{{ invoice.total_amount }}|{{
invoice.tax_amount }}
{% for tax in invoice.taxes -%}

View file

@ -10,6 +10,10 @@ msgctxt "field:account.invoice,is_edi:"
msgid "Is EDI"
msgstr "Es EDI"
msgctxt "field:account.invoice.line,code_ean13:"
msgid "Code EAN13"
msgstr "Codi EAN13"
msgctxt "field:invoice.edi,base_amount:"
msgid "Base Amount"
msgstr "Import Base"
@ -142,6 +146,10 @@ msgctxt "field:invoice.edi,type_:"
msgid "Document Type"
msgstr "Tipus de document"
msgctxt "field:invoice.edi.configuration,automatic_edi_invoice_out:"
msgid "Send EDI file automatically"
msgstr "Enviar fitxer EDI automáticament"
msgctxt "field:invoice.edi.configuration,edi_files_path:"
msgid "EDI Invoice Inbox Path"
msgstr "EDI Ruta Factura Proveïdor"
@ -513,6 +521,10 @@ msgctxt "model:ir.message,text:msg_path_not_found"
msgid "EDI path not found. Please check the configuration."
msgstr "No s'ha trobat la ruta EDI. Si us plau comprova la configuració "
msgctxt "model:ir.message,text:msg_send_edi_invoice"
msgid "The invoice %(invoice)s will processed and sended the EDI file."
msgstr "De la factura %(invoice)s serà processat i enviat el fitxer EDI."
msgctxt "model:ir.model.button,string:generate_edi_file"
msgid "Generate EDI"
msgstr "Generar EDI"
@ -545,10 +557,6 @@ msgctxt "selection:invoice.edi,function_:"
msgid "Original"
msgstr "Original"
msgctxt "selection:invoice.edi,payment_type_value:"
msgid ""
msgstr "Tercer Editat"
msgctxt "selection:invoice.edi,payment_type_value:"
msgid "Account Bank"
msgstr "Compte bancari"

View file

@ -10,6 +10,10 @@ msgctxt "field:account.invoice,is_edi:"
msgid "Is EDI"
msgstr "Es EDI"
msgctxt "field:account.invoice.line,code_ean13:"
msgid "Code EAN13"
msgstr "Código EAN13"
msgctxt "field:invoice.edi,base_amount:"
msgid "Base Amount"
msgstr "Importe base"
@ -142,6 +146,10 @@ msgctxt "field:invoice.edi,type_:"
msgid "Document Type"
msgstr "Tipo de documento"
msgctxt "field:invoice.edi.configuration,automatic_edi_invoice_out:"
msgid "Send EDI file automatically"
msgstr "Enviar fichero eDI automáticamente"
msgctxt "field:invoice.edi.configuration,edi_files_path:"
msgid "EDI Invoice Inbox Path"
msgstr "EDI Ruta Factura Proveedor"
@ -515,6 +523,10 @@ msgctxt "model:ir.message,text:msg_path_not_found"
msgid "EDI path not found. Please check the configuration."
msgstr "No se ha encontrado la ruta EDI. Porfavor comprobar la confguración"
msgctxt "model:ir.message,text:msg_send_edi_invoice"
msgid "The invoice %(invoice)s will processed and sended the EDI file."
msgstr "De la factura %(invoice)s será procesado y enviado el fichero EDI."
msgctxt "model:ir.model.button,string:generate_edi_file"
msgid "Generate EDI"
msgstr "Generar EDI"

View file

@ -18,5 +18,8 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_path_not_found">
<field name="text">EDI path not found. Please check the configuration.</field>
</record>
<record model="ir.message" id="msg_send_edi_invoice">
<field name="text">The invoice %(invoice)s will processed and sended the EDI file.</field>
</record>
</data>
</tryton>
</tryton>

View file

@ -10,5 +10,6 @@ extras_depend:
sale
sale_edi_ediversa
xml:
configuration.xml
invoice.xml
message.xml

View file

@ -4,8 +4,10 @@ this repository contains the full copyright notices and license terms. -->
<form>
<label name="edi_files_path"/>
<field name="edi_files_path"/>
<label name="separator"/>
<field name="separator"/>
<label name="outbox_path_edi"/>
<field name="outbox_path_edi"/>
<label name="automatic_edi_invoice_out"/>
<field name="automatic_edi_invoice_out"/>
<label name="separator"/>
<field name="separator"/>
</form>

View file

@ -1,9 +0,0 @@
<?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" position="inside">
<label name="outbox_path_edi"/>
<field name="outbox_path_edi"/>
</xpath>
</data>