Create shipment and lots, translated module

This commit is contained in:
MarinaNico 2021-01-18 12:16:33 +01:00
parent 047ff6541f
commit 3664dc3400
11 changed files with 1087 additions and 445 deletions

View file

@ -12,8 +12,5 @@ def register():
edi_shipment.EdiShipmentInLine,
edi_shipment.EdiShipmentIn,
edi_shipment.EdiShipmentInLineQty,
shipment.Cron,
shipment.Move,
shipment.ShipmentIn,
shipment.StockConfiguration,
edi_shipment.StockConfiguration,
module='stock_shipment_in_edi', type_='model')

View file

@ -8,10 +8,10 @@ from trytond.transaction import Transaction
import os
from trytond.modules.account_invoice_edi.invoice import (SupplierEdiMixin,
SUPPLIER_TYPE)
# from trytond.exceptions import UserError, UserWarning
# from trytond.i18n import gettext
from datetime import datetime
from decimal import Decimal
from trytond.i18n import gettext
from trytond.exceptions import UserError
DEFAULT_FILES_LOCATION = '/tmp/'
MODULE_PATH = os.path.dirname(os.path.abspath(__file__))
@ -43,6 +43,12 @@ class Cron(metaclass=PoolMeta):
('edi.shipment.in|import_shipment_in',
'Import EDI Shipment In Orders')])
class StockConfiguration(metaclass=PoolMeta):
__name__ = 'stock.configuration'
inbox_path_edi = fields.Char('Inbox Path EDI')
class SupplierEdi(SupplierEdiMixin, ModelSQL, ModelView):
'Supplier Edi'
__name__ = 'edi.shipment.supplier'
@ -51,7 +57,7 @@ class SupplierEdi(SupplierEdiMixin, ModelSQL, ModelView):
class EdiShipmentReference(ModelSQL, ModelView):
'Account Invoice Reference'
'Shipment In Reference'
__name__ = 'edi.shipment.in.reference'
# RFF, RFFLIN
@ -165,8 +171,8 @@ class EdiShipmentInLine(ModelSQL, ModelView):
'Dimension', readonly=True)
dimension_unit = fields.Selection([('', ''), ('CEL', 'Celsius Degrees')],
'Dimension Unit', readonly=True)
dimension_qualifier = fields.Selection([('', ''), ('SO', 'Storage Limiet')],
'Storage Limiet', readonly=True)
dimension_qualifier = fields.Selection([('', ''), ('SO', 'Storage Limit')],
'Storage Limit', readonly=True)
dimension_min = fields.Numeric('Min', readonly=True)
dimension_max = fields.Numeric('Max', readonly=True)
marking_instructions = fields.Selection([('', ''),
@ -283,7 +289,7 @@ class EdiShipmentInLine(ModelSQL, ModelView):
for move in purchase.moves:
if move.product == product:
ref = REF()
ref.type_ = 'move'
ref.type_ = 'ON'
ref.origin = 'stock.move,%s ' % move.id
self.references += (ref,)
@ -305,6 +311,7 @@ class EdiShipmentInLineQty(ModelSQL, ModelView):
edi_shipment_line = fields.Many2One('edi.shipment.in.line', 'Shipment Line',
readonly=True)
class EdiShipmentIn(ModelSQL, ModelView):
'Edi shipment In'
__name__ = 'edi.shipment.in'
@ -324,14 +331,14 @@ class EdiShipmentIn(ModelSQL, ModelView):
'Supplier', readonly=True)
manual_party = fields.Many2One('party.party', 'Manual Party')
shipment = fields.Many2One('stock.shipment.in', 'Shipment')
party = fields.Function(fields.Many2One('party.party', 'Invoice Party'),
party = fields.Function(fields.Many2One('party.party', 'Shipment Party'),
'get_party', searcher='search_party')
@classmethod
def __setup__(cls):
super().__setup__()
cls._buttons.update({
'create_shipments': {},
'create_shipment': {},
'search_references': {}
})
@ -412,18 +419,24 @@ class EdiShipmentIn(ModelSQL, ModelView):
# Not implemented
pass
def get_quantity(line):
for qty in line.quantities:
if qty.type_ == '12':
return float(qty.quantity)
@classmethod
def import_edi_file(cls, shipments, data):
pool = Pool()
Shipment = pool.get('edi.shipment.in')
Line = pool.get('edi.shipment.in.line')
ShipmentEdi = pool.get('edi.shipment.in')
ShipmentEdiLine = pool.get('edi.shipment.in.line')
SupplierEdi = pool.get('edi.shipment.supplier')
# Configuration = pool.get('stock.configuration')
# config = Configuration(1)
separator = '|' # TODO config.separator
shipment = None
shipment_edi = None
shipment_line = None
document_type = data.pop(0).replace('\n', '').replace('\r', '')
if document_type != 'DESADV_D_96A_UN_EAN005':
@ -433,32 +446,32 @@ class EdiShipmentIn(ModelSQL, ModelView):
line = line.split(separator)
msg_id = line.pop(0)
if msg_id == 'BGM':
shipment = Shipment()
shipment.read_BGM(line)
shipment_edi = ShipmentEdi()
shipment_edi.read_BGM(line)
elif msg_id == 'LIN':
# if shipment_line:
# shipment_line.search_related(shipment)
shipment_line = Line()
shipment_line.read_LIN(line)
if not getattr(shipment, 'lines', False):
shipment.lines = []
shipment.lines += (shipment_line,)
shipment_edi_line = ShipmentEdiLine()
shipment_edi_line.read_LIN(line)
if not getattr(shipment_edi, 'lines', False):
shipment_edi.lines = []
shipment_edi.lines += (shipment_edi_line,)
elif 'LIN' in msg_id:
getattr(shipment_line, 'read_%s' % msg_id)(line)
getattr(shipment_edi_line, 'read_%s' % msg_id)(line)
elif msg_id in [x[0] for x in SUPPLIER_TYPE]:
supplier = SupplierEdi()
getattr(supplier, 'read_%s' % msg_id)(line)
supplier.search_party()
if not getattr(shipment, 'suppliers', False):
shipment.suppliers = []
shipment.suppliers += (supplier,)
if not getattr(shipment_edi, 'suppliers', False):
shipment_edi.suppliers = []
shipment_edi.suppliers += (supplier,)
elif 'NAD' in msg_id:
continue
else:
getattr(shipment, 'read_%s' % msg_id)(line)
getattr(shipment_edi, 'read_%s' % msg_id)(line)
# invoice_line.search_related(shipment)
return shipment
return shipment_edi
def add_attachment(self, attachment, filename=None):
pool = Pool()
@ -490,7 +503,6 @@ class EdiShipmentIn(ModelSQL, ModelView):
if fname[-4:].lower() not in KNOWN_EXTENSIONS:
continue
with open(fname, 'r', encoding='latin-1') as fp:
print("fname:", fname)
data = fp.readlines()
shipment = cls.import_edi_file([], data)
@ -507,12 +519,24 @@ class EdiShipmentIn(ModelSQL, ModelView):
# for shipment, (data, basename) in attachments.items():
# shipment.add_attachment(data, basename)
# if files_to_delete:
# for file in files_to_delete:
# os.remove(file)
if files_to_delete:
for file in files_to_delete:
os.remove(file)
cls.search_references(to_save)
def _get_new_lot(self, line, quantity):
pool = Pool()
Lot = pool.get('stock.lot')
if line.expiration_date:
today = datetime.today().date()
lot = Lot()
lot.product = line.product
lot.expiration_date = line.expiration_date
lot.on_change_product()
return lot
@classmethod
@ModelView.button
def search_references(cls, edi_shipments):
@ -525,3 +549,67 @@ class EdiShipmentIn(ModelSQL, ModelView):
eline.search_related(edi_shipment)
to_save.append(eline)
Line.save(to_save)
@classmethod
@ModelView.button
def create_shipment(cls, edi_shipments):
ShipmentIn = Pool().get('stock.shipment.in')
Move = Pool().get('stock.move')
Lot = Pool().get('stock.lot')
Purchase = Pool().get('purchase.purchase')
to_save = []
move_to_save = []
for edi_shipment in edi_shipments:
if edi_shipment.shipment:
continue
shipment = ShipmentIn()
for reference in edi_shipment.references:
if reference.type_ == 'ON' and reference.origin:
if isinstance(reference.origin, Purchase):
shipment.warehouse = reference.origin.warehouse
break
if reference.type_ == 'ON' and not reference.origin:
raise UserError(gettext(
'stock_shipment_in_edi.msg_no_purchase_ref'))
shipment.reference = edi_shipment.number
shipment.supplier = edi_shipment.party.id
edi_shipment.shipment = shipment
for line in edi_shipment.lines:
if not line.product:
raise UserError(gettext(
'stock_shipment_in_edi.msg_no_product',
number=line.line_number))
if not line.references:
raise UserError(gettext(
'stock_shipment_in_edi.msg_no_move_ref',
number=line.line_number))
for ref in line.references:
if ref.origin not in move_to_save:
quantity = cls.get_quantity(line)
move = ref.origin
move.shipment = shipment
move.quantity = quantity
move.lot = cls._get_new_lot(cls, line, quantity)
move_to_save.append(move)
else:
quantity = cls.get_quantity(line)
move, = ref.origin.copy([ref.origin])
move.shipment = shipment
move.quantity = quantity
move.lot = cls._get_new_lot(cls, line, quantity)
move_to_save.append(move)
edi_shipment.save()
to_save.append(shipment)
if to_save:
ShipmentIn.save(to_save)
if move_to_save:
Move.save(move_to_save)

View file

@ -2,33 +2,493 @@
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:stock.configuration,errors_path_edi:"
msgid "Errors Path"
msgstr "Path d'errors"
msgctxt "field:edi.shipment.in,company:"
msgid "Company"
msgstr "Empresa"
msgctxt "field:edi.shipment.in,estimated_date:"
msgid "Estimated Date"
msgstr "Data estimada"
msgctxt "field:edi.shipment.in,expedition_date:"
msgid "Expedition Date"
msgstr "Data d'expedició"
msgctxt "field:edi.shipment.in,function_:"
msgid "Function Type"
msgstr "Tipus de funció"
msgctxt "field:edi.shipment.in,lines:"
msgid "Shipment"
msgstr "Albarà"
msgctxt "field:edi.shipment.in,manual_party:"
msgid "Manual Party"
msgstr "Tercer manual"
msgctxt "field:edi.shipment.in,number:"
msgid "Number"
msgstr "Número"
msgctxt "field:edi.shipment.in,party:"
msgid "Shipment Party"
msgstr "Tercer de l'enviament"
msgctxt "field:edi.shipment.in,references:"
msgid "References"
msgstr "Referències"
msgctxt "field:edi.shipment.in,shipment:"
msgid "Shipment"
msgstr "Albarà"
msgctxt "field:edi.shipment.in,suppliers:"
msgid "Supplier"
msgstr "Proveïdor"
msgctxt "field:edi.shipment.in,type_:"
msgid "Document Type"
msgstr "Tipus de document"
msgctxt "field:edi.shipment.in.line,code:"
msgid "Code"
msgstr "Codi"
msgctxt "field:edi.shipment.in.line,code_type:"
msgid "Code Type"
msgstr "Tipus de codi"
msgctxt "field:edi.shipment.in.line,desccod:"
msgid "Codification description"
msgstr "Descripció codificada"
msgctxt "field:edi.shipment.in.line,description:"
msgid "Description"
msgstr "Descripció"
msgctxt "field:edi.shipment.in.line,description_type:"
msgid "Type of Description"
msgstr "Tipus de descripció"
msgctxt "field:edi.shipment.in.line,dimension:"
msgid "Dimension"
msgstr " Dimensió"
msgctxt "field:edi.shipment.in.line,dimension_max:"
msgid "Max"
msgstr "Max"
msgctxt "field:edi.shipment.in.line,dimension_min:"
msgid "Min"
msgstr "Min"
msgctxt "field:edi.shipment.in.line,dimension_qualifier:"
msgid "Storage Limit"
msgstr "Límit d'emmagatzematge"
msgctxt "field:edi.shipment.in.line,dimension_unit:"
msgid "Dimension Unit"
msgstr " Unitat de dimensió"
msgctxt "field:edi.shipment.in.line,edi_shipment:"
msgid "Shipment"
msgstr "Albarà"
msgctxt "field:edi.shipment.in.line,expiration_date:"
msgid "Expiration Date"
msgstr " Data de caducitat"
msgctxt "field:edi.shipment.in.line,line_number:"
msgid "Line Number"
msgstr "Número de línia"
msgctxt "field:edi.shipment.in.line,lot_number:"
msgid "Lot Number"
msgstr "Número de lot"
msgctxt "field:edi.shipment.in.line,marking_instructions:"
msgid "Marking Instructions"
msgstr "Instruccions de marcatge"
msgctxt "field:edi.shipment.in.line,packing_date:"
msgid "Packing Date"
msgstr "Data dembalatge"
msgctxt "field:edi.shipment.in.line,product:"
msgid "Product"
msgstr "Producte"
msgctxt "field:edi.shipment.in.line,purchaser_code:"
msgid "Purchaser Code"
msgstr "Codi del comprador"
msgctxt "field:edi.shipment.in.line,quantities:"
msgid "Quantities"
msgstr "Quantitats"
msgctxt "field:edi.shipment.in.line,references:"
msgid "References"
msgstr "Referències"
msgctxt "field:edi.shipment.in.line,serial_number:"
msgid "Serial Number"
msgstr "Número de serie"
msgctxt "field:edi.shipment.in.line,supplier_code:"
msgid "Supplier Code"
msgstr "Codi de proveïdor"
msgctxt "field:edi.shipment.in.line.qty,difference:"
msgid "Difference"
msgstr "Diferència"
msgctxt "field:edi.shipment.in.line.qty,edi_shipment_line:"
msgid "Shipment Line"
msgstr "Línia d'albarà"
msgctxt "field:edi.shipment.in.line.qty,quantity:"
msgid "Quantity"
msgstr "Quantitat"
msgctxt "field:edi.shipment.in.line.qty,type_:"
msgid "Quantity Type"
msgstr "Tipus de quantitat"
msgctxt "field:edi.shipment.in.line.qty,unit:"
msgid "Unit"
msgstr "Unitat"
msgctxt "field:edi.shipment.in.reference,edi_shipment:"
msgid "Shipment"
msgstr "Albarà"
msgctxt "field:edi.shipment.in.reference,edi_shipment_in_line:"
msgid "Line"
msgstr "Línia"
msgctxt "field:edi.shipment.in.reference,origin:"
msgid "Reference"
msgstr "Referència"
msgctxt "field:edi.shipment.in.reference,reference:"
msgid "Reference"
msgstr "Referència"
msgctxt "field:edi.shipment.in.reference,reference_date:"
msgid "Reference Date"
msgstr "Data de referència"
msgctxt "field:edi.shipment.in.reference,type_:"
msgid "Reference Code"
msgstr "Codi de referència"
msgctxt "field:edi.shipment.supplier,account_bank:"
msgid "Account Bank"
msgstr "Compte bancari"
msgctxt "field:edi.shipment.supplier,city:"
msgid "City"
msgstr "Ciutat"
msgctxt "field:edi.shipment.supplier,commercial_register:"
msgid "Comercial Register"
msgstr "Registre comercial"
msgctxt "field:edi.shipment.supplier,country_code:"
msgid "Country_code"
msgstr ""
msgctxt "field:edi.shipment.supplier,edi_code:"
msgid "Edi Code"
msgstr "Codi Edi"
msgctxt "field:edi.shipment.supplier,edi_shipment:"
msgid "Edi Shipment"
msgstr "Albarà Edi"
msgctxt "field:edi.shipment.supplier,name:"
msgid "Name"
msgstr "Nom"
msgctxt "field:edi.shipment.supplier,party:"
msgid "Party"
msgstr "Tercers"
msgctxt "field:edi.shipment.supplier,street:"
msgid "Street"
msgstr "Carrer"
msgctxt "field:edi.shipment.supplier,type_:"
msgid "Type"
msgstr "Tipus"
msgctxt "field:edi.shipment.supplier,vat:"
msgid "Vat"
msgstr "NIF"
msgctxt "field:edi.shipment.supplier,zip:"
msgid "zip"
msgstr "zip"
msgctxt "field:stock.configuration,inbox_path_edi:"
msgid "Inbox Path EDI"
msgstr "Path d'entrada EDI"
msgctxt "field:stock.configuration,template_order_response_edi:"
msgid "Template EDI Used for Response"
msgstr "Plantilla EDI de Resposta"
msgctxt "model:edi.shipment.in,name:"
msgid "Edi shipment In"
msgstr "Albarà Edi de proveïdor"
msgctxt "field:stock.move,edi_description:"
msgid "EDI Description"
msgstr "Descripció EDI"
msgctxt "model:edi.shipment.in.line,name:"
msgid "Edi Shipment in Line"
msgstr "Línia d'albarà Edi de proveïdor"
msgctxt "field:stock.move,edi_quantity:"
msgid "EDI Quantity"
msgstr "Quantitat EDI"
msgctxt "model:edi.shipment.in.line.qty,name:"
msgid "Edi Shipment in Line Qty"
msgstr "Quantitat línia d'albarà Edi de proveïdor"
msgctxt "model:ir.cron,name:cron_import_edi_shipment_in"
msgctxt "model:edi.shipment.in.reference,name:"
msgid "Shipment In Reference"
msgstr "Referència albará de proveïdor"
msgctxt "model:edi.shipment.supplier,name:"
msgid "Supplier Edi"
msgstr "Proveïdor Edi"
msgctxt "model:ir.action,name:act_edi_shipment_in_form"
msgid "Edi Shipment"
msgstr "Albarà Edi"
msgctxt "model:ir.cron,name:"
msgid "Import EDI Supplier Shipments"
msgstr "Importar Albarans de Proveïdor EDI"
msgctxt "model:res.user,name:user_edi_shipment_in"
msgid "Cron EDI Shipments"
msgstr "Cron Albarans EDI"
msgctxt "model:ir.message,text:msg_no_move_ref"
msgid "There is not move reference in line number %(number)s."
msgstr " No hi ha referència de moviment a la línia número %(number)s."
msgctxt "model:ir.message,text:msg_no_product"
msgid "There is not product in line number %(number)s."
msgstr "No hi ha producte a la línia número %(number)s."
msgctxt "model:ir.message,text:msg_no_purchase_ref"
msgid "There is not purchase origin in reference."
msgstr " No hi ha origen de compra a les referències de l'albarà edi."
msgctxt "model:ir.ui.menu,name:menu_edi_shipment"
msgid "Edi Shipment"
msgstr "Albarà Edi"
msgctxt "model:ir.ui.menu,name:menuitem_edi_shipment"
msgid "Edi Shipment"
msgstr "Albarà Edi"
msgctxt "selection:edi.shipment.in,function_:"
msgid "Copy"
msgstr "Copiar"
msgctxt "selection:edi.shipment.in,function_:"
msgid "Original"
msgstr "Original"
msgctxt "selection:edi.shipment.in,type_:"
msgid "Expedition Warning"
msgstr " Avís d'expedició"
msgctxt "selection:edi.shipment.in.line,code_type:"
msgid "DUN14"
msgstr "DUN14"
msgctxt "selection:edi.shipment.in.line,code_type:"
msgid "EAN13"
msgstr "EAN13"
msgctxt "selection:edi.shipment.in.line,code_type:"
msgid "EAN14"
msgstr "EAN14"
msgctxt "selection:edi.shipment.in.line,code_type:"
msgid "EAN8"
msgstr "EAN8"
msgctxt "selection:edi.shipment.in.line,code_type:"
msgid "EN"
msgstr "EN"
msgctxt "selection:edi.shipment.in.line,desccod:"
msgid "Consumption Unit"
msgstr "Unitat de consum"
msgctxt "selection:edi.shipment.in.line,desccod:"
msgid "Dispatch Unit"
msgstr "Unitat d'enviament"
msgctxt "selection:edi.shipment.in.line,description_type:"
msgid "Codificated Description"
msgstr "Descripció codificada"
msgctxt "selection:edi.shipment.in.line,description_type:"
msgid "Free Description"
msgstr "Descripció lliure"
msgctxt "selection:edi.shipment.in.line,dimension:"
msgid "Temperature"
msgstr " Temperatura"
msgctxt "selection:edi.shipment.in.line,dimension_qualifier:"
msgid "Storage Limit"
msgstr "Límit d'emmagatzematge"
msgctxt "selection:edi.shipment.in.line,dimension_unit:"
msgid "Celsius Degrees"
msgstr " Graus centígrads"
msgctxt "selection:edi.shipment.in.line,marking_instructions:"
msgid "Supplier Instructions"
msgstr " Instruccions del proveïdor"
msgctxt "selection:edi.shipment.in.line.qty,difference:"
msgid "Partial Shipment"
msgstr "Albarà parcial"
msgctxt "selection:edi.shipment.in.line.qty,difference:"
msgid "Partial Shipment but Complete"
msgstr "Albará parcial però complet"
msgctxt "selection:edi.shipment.in.line.qty,type_:"
msgid "21"
msgstr "21"
msgctxt "selection:edi.shipment.in.line.qty,type_:"
msgid "45E"
msgstr "45E"
msgctxt "selection:edi.shipment.in.line.qty,type_:"
msgid "Free Quantity"
msgstr " Quantitat lliure"
msgctxt "selection:edi.shipment.in.line.qty,type_:"
msgid "Quantity Sended"
msgstr "Quantitat enviada"
msgctxt "selection:edi.shipment.in.line.qty,type_:"
msgid "Quantity on package"
msgstr "Quantitat al paquet"
msgctxt "selection:edi.shipment.in.line.qty,unit:"
msgid "EA"
msgstr "EA"
msgctxt "selection:edi.shipment.in.line.qty,unit:"
msgid "Gramo"
msgstr "Gram"
msgctxt "selection:edi.shipment.in.line.qty,unit:"
msgid "Kilogramo"
msgstr "Kilogram"
msgctxt "selection:edi.shipment.in.line.qty,unit:"
msgid "Litro"
msgstr "Litre"
msgctxt "selection:edi.shipment.in.line.qty,unit:"
msgid "Pieza"
msgstr "Peça"
msgctxt "selection:edi.shipment.in.reference,type_:"
msgid "Line Number"
msgstr "Número de línia"
msgctxt "selection:edi.shipment.in.reference,type_:"
msgid "Purchase"
msgstr "Compra"
msgctxt "selection:edi.shipment.in.reference,type_:"
msgid "Shipment"
msgstr "Albarà"
msgctxt "selection:edi.shipment.in.reference,type_:"
msgid "VN"
msgstr "VN"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Endorser"
msgstr "Provador"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Final Receiver"
msgstr " Receptor final"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Invoice Issuer"
msgstr " Emissor de factures"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Invoice Receiver"
msgstr " Receptor de factures"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Legal Purchaser"
msgstr "Comprador legal"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Legal Supplier"
msgstr "Proveïdor legal"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "NAD"
msgstr ""
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "NADMR"
msgstr ""
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "NADPE"
msgstr ""
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "NADPW"
msgstr ""
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Payment Issuer"
msgstr "Emissor de pagaments"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Purchaser"
msgstr "Comprador"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Sender"
msgstr " Remitent"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Stock Receiver"
msgstr " Receptor destoc"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Supplier"
msgstr "Proveïdor"
msgctxt "selection:ir.cron,method:"
msgid "Import EDI Shipment In Orders"
msgstr "Importar comandes albará de proveïdor EDI"
msgctxt "view:edi.shipment.in:"
msgid "Create Shipment"
msgstr "Crear albarà"
msgctxt "view:edi.shipment.in:"
msgid "Lines"
msgstr "Línies"
msgctxt "view:edi.shipment.in:"
msgid "Parties"
msgstr "Tercers"
msgctxt "view:edi.shipment.in:"
msgid "Search References"
msgstr " Cerca referències"
msgctxt "view:stock.configuration:"
msgid "EDI"

View file

@ -2,33 +2,493 @@
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:stock.configuration,errors_path_edi:"
msgid "Errors Path"
msgstr "Path de errores"
msgctxt "field:edi.shipment.in,company:"
msgid "Company"
msgstr "Empresa"
msgctxt "field:edi.shipment.in,estimated_date:"
msgid "Estimated Date"
msgstr "Fecha estimada"
msgctxt "field:edi.shipment.in,expedition_date:"
msgid "Expedition Date"
msgstr "Fecha de expedición"
msgctxt "field:edi.shipment.in,function_:"
msgid "Function Type"
msgstr "Tipo de función"
msgctxt "field:edi.shipment.in,lines:"
msgid "Shipment"
msgstr "Albarán"
msgctxt "field:edi.shipment.in,manual_party:"
msgid "Manual Party"
msgstr "Tercero manual"
msgctxt "field:edi.shipment.in,number:"
msgid "Number"
msgstr "Número"
msgctxt "field:edi.shipment.in,party:"
msgid "Shipment Party"
msgstr "Tercero del envío"
msgctxt "field:edi.shipment.in,references:"
msgid "References"
msgstr "Referencias"
msgctxt "field:edi.shipment.in,shipment:"
msgid "Shipment"
msgstr "Albarán"
msgctxt "field:edi.shipment.in,suppliers:"
msgid "Supplier"
msgstr "Proveedor"
msgctxt "field:edi.shipment.in,type_:"
msgid "Document Type"
msgstr "Tipo de documento"
msgctxt "field:edi.shipment.in.line,code:"
msgid "Code"
msgstr "Código"
msgctxt "field:edi.shipment.in.line,code_type:"
msgid "Code Type"
msgstr "Tipo de código"
msgctxt "field:edi.shipment.in.line,desccod:"
msgid "Codification description"
msgstr "Descripción codificada"
msgctxt "field:edi.shipment.in.line,description:"
msgid "Description"
msgstr "Descripción"
msgctxt "field:edi.shipment.in.line,description_type:"
msgid "Type of Description"
msgstr "Tipo de descripción"
msgctxt "field:edi.shipment.in.line,dimension:"
msgid "Dimension"
msgstr "Dimensión"
msgctxt "field:edi.shipment.in.line,dimension_max:"
msgid "Max"
msgstr "Max"
msgctxt "field:edi.shipment.in.line,dimension_min:"
msgid "Min"
msgstr "Min"
msgctxt "field:edi.shipment.in.line,dimension_qualifier:"
msgid "Storage Limit"
msgstr " Límite de almacenamiento"
msgctxt "field:edi.shipment.in.line,dimension_unit:"
msgid "Dimension Unit"
msgstr "Unidad de dimensión"
msgctxt "field:edi.shipment.in.line,edi_shipment:"
msgid "Shipment"
msgstr "Albarán"
msgctxt "field:edi.shipment.in.line,expiration_date:"
msgid "Expiration Date"
msgstr "Fecha de caducidad"
msgctxt "field:edi.shipment.in.line,line_number:"
msgid "Line Number"
msgstr "Número de línea"
msgctxt "field:edi.shipment.in.line,lot_number:"
msgid "Lot Number"
msgstr "Número de lote"
msgctxt "field:edi.shipment.in.line,marking_instructions:"
msgid "Marking Instructions"
msgstr " Instrucciones de marcado"
msgctxt "field:edi.shipment.in.line,packing_date:"
msgid "Packing Date"
msgstr "Fecha de embalaje"
msgctxt "field:edi.shipment.in.line,product:"
msgid "Product"
msgstr "Producto"
msgctxt "field:edi.shipment.in.line,purchaser_code:"
msgid "Purchaser Code"
msgstr "Código del comprador"
msgctxt "field:edi.shipment.in.line,quantities:"
msgid "Quantities"
msgstr "Cantidades"
msgctxt "field:edi.shipment.in.line,references:"
msgid "References"
msgstr "Referencias"
msgctxt "field:edi.shipment.in.line,serial_number:"
msgid "Serial Number"
msgstr "Número de serie"
msgctxt "field:edi.shipment.in.line,supplier_code:"
msgid "Supplier Code"
msgstr "Código de proveedor"
msgctxt "field:edi.shipment.in.line.qty,difference:"
msgid "Difference"
msgstr ""
msgctxt "field:edi.shipment.in.line.qty,edi_shipment_line:"
msgid "Shipment Line"
msgstr "Línea de albarán"
msgctxt "field:edi.shipment.in.line.qty,quantity:"
msgid "Quantity"
msgstr "Cantidad"
msgctxt "field:edi.shipment.in.line.qty,type_:"
msgid "Quantity Type"
msgstr "Tipo de cantidad"
msgctxt "field:edi.shipment.in.line.qty,unit:"
msgid "Unit"
msgstr "Unidad"
msgctxt "field:edi.shipment.in.reference,edi_shipment:"
msgid "Shipment"
msgstr "Albarán"
msgctxt "field:edi.shipment.in.reference,edi_shipment_in_line:"
msgid "Line"
msgstr "Línea"
msgctxt "field:edi.shipment.in.reference,origin:"
msgid "Reference"
msgstr "Referencia"
msgctxt "field:edi.shipment.in.reference,reference:"
msgid "Reference"
msgstr "Referencia"
msgctxt "field:edi.shipment.in.reference,reference_date:"
msgid "Reference Date"
msgstr "Fecha de referencia"
msgctxt "field:edi.shipment.in.reference,type_:"
msgid "Reference Code"
msgstr "Código de referencia"
msgctxt "field:edi.shipment.supplier,account_bank:"
msgid "Account Bank"
msgstr "Cuenta bancaria"
msgctxt "field:edi.shipment.supplier,city:"
msgid "City"
msgstr "Ciudad"
msgctxt "field:edi.shipment.supplier,commercial_register:"
msgid "Comercial Register"
msgstr "Registro comercial"
msgctxt "field:edi.shipment.supplier,country_code:"
msgid "Country_code"
msgstr "Código de país"
msgctxt "field:edi.shipment.supplier,edi_code:"
msgid "Edi Code"
msgstr "Código Edi"
msgctxt "field:edi.shipment.supplier,edi_shipment:"
msgid "Edi Shipment"
msgstr "Albarán Edi"
msgctxt "field:edi.shipment.supplier,name:"
msgid "Name"
msgstr "Nombre"
msgctxt "field:edi.shipment.supplier,party:"
msgid "Party"
msgstr "Terceros"
msgctxt "field:edi.shipment.supplier,street:"
msgid "Street"
msgstr "Calle"
msgctxt "field:edi.shipment.supplier,type_:"
msgid "Type"
msgstr "Tipo"
msgctxt "field:edi.shipment.supplier,vat:"
msgid "Vat"
msgstr "NIF"
msgctxt "field:edi.shipment.supplier,zip:"
msgid "zip"
msgstr "zip"
msgctxt "field:stock.configuration,inbox_path_edi:"
msgid "Inbox Path EDI"
msgstr "Path de entrada EDI"
msgctxt "field:stock.configuration,template_order_response_edi:"
msgid "Template EDI Used for Response"
msgstr "Plantilla EDI usada para la Respuesta"
msgctxt "model:edi.shipment.in,name:"
msgid "Edi shipment In"
msgstr "Albarán Edi de proveedor"
msgctxt "field:stock.move,edi_description:"
msgid "EDI Description"
msgstr "Descripción EDI"
msgctxt "model:edi.shipment.in.line,name:"
msgid "Edi Shipment in Line"
msgstr "Línea de albarán Edi de proveedor"
msgctxt "field:stock.move,edi_quantity:"
msgid "EDI Quantity"
msgstr "Cantidad EDI"
msgctxt "model:edi.shipment.in.line.qty,name:"
msgid "Edi Shipment in Line Qty"
msgstr ""
msgctxt "model:ir.cron,name:cron_import_edi_shipment_in"
msgctxt "model:edi.shipment.in.reference,name:"
msgid "Shipment In Reference"
msgstr "Referencia albarán de proveedor"
msgctxt "model:edi.shipment.supplier,name:"
msgid "Supplier Edi"
msgstr "Proveedor Edi"
msgctxt "model:ir.action,name:act_edi_shipment_in_form"
msgid "Edi Shipment"
msgstr "Albarán Edi"
msgctxt "model:ir.cron,name:"
msgid "Import EDI Supplier Shipments"
msgstr "Importar Albaranes de Proveedor EDI"
msgctxt "model:res.user,name:user_edi_shipment_in"
msgid "Cron EDI Shipments"
msgstr "Cron Albaranes EDI"
msgctxt "model:ir.message,text:msg_no_move_ref"
msgid "There is not move reference in line number %(number)s."
msgstr "No hay referencia de movimiento en la línia número %(number)s."
msgctxt "model:ir.message,text:msg_no_product"
msgid "There is not product in line number %(number)s."
msgstr " No hay producto en la línea número %(number)s."
msgctxt "model:ir.message,text:msg_no_purchase_ref"
msgid "There is not purchase origin in reference."
msgstr " No hay origen de compra en las referencias del albarán edi."
msgctxt "model:ir.ui.menu,name:menu_edi_shipment"
msgid "Edi Shipment"
msgstr "Albarán Edi"
msgctxt "model:ir.ui.menu,name:menuitem_edi_shipment"
msgid "Edi Shipment"
msgstr "Albarán Edi"
msgctxt "selection:edi.shipment.in,function_:"
msgid "Copy"
msgstr "Copiar"
msgctxt "selection:edi.shipment.in,function_:"
msgid "Original"
msgstr "Original"
msgctxt "selection:edi.shipment.in,type_:"
msgid "Expedition Warning"
msgstr "Aviso de expedición"
msgctxt "selection:edi.shipment.in.line,code_type:"
msgid "DUN14"
msgstr "DUN14"
msgctxt "selection:edi.shipment.in.line,code_type:"
msgid "EAN13"
msgstr "EAN13"
msgctxt "selection:edi.shipment.in.line,code_type:"
msgid "EAN14"
msgstr "EAN14"
msgctxt "selection:edi.shipment.in.line,code_type:"
msgid "EAN8"
msgstr "EAN8"
msgctxt "selection:edi.shipment.in.line,code_type:"
msgid "EN"
msgstr "EN"
msgctxt "selection:edi.shipment.in.line,desccod:"
msgid "Consumption Unit"
msgstr " Unidad de consumo"
msgctxt "selection:edi.shipment.in.line,desccod:"
msgid "Dispatch Unit"
msgstr "Unidad de envío"
msgctxt "selection:edi.shipment.in.line,description_type:"
msgid "Codificated Description"
msgstr "Descripción codificada"
msgctxt "selection:edi.shipment.in.line,description_type:"
msgid "Free Description"
msgstr "Descripción libre"
msgctxt "selection:edi.shipment.in.line,dimension:"
msgid "Temperature"
msgstr "Temperatura"
msgctxt "selection:edi.shipment.in.line,dimension_qualifier:"
msgid "Storage Limit"
msgstr " Límite de almacenamiento"
msgctxt "selection:edi.shipment.in.line,dimension_unit:"
msgid "Celsius Degrees"
msgstr "Grados centígrados"
msgctxt "selection:edi.shipment.in.line,marking_instructions:"
msgid "Supplier Instructions"
msgstr " Instrucciones del proveedor"
msgctxt "selection:edi.shipment.in.line.qty,difference:"
msgid "Partial Shipment"
msgstr "Albarán parcial"
msgctxt "selection:edi.shipment.in.line.qty,difference:"
msgid "Partial Shipment but Complete"
msgstr "Albarán parcial pero completo"
msgctxt "selection:edi.shipment.in.line.qty,type_:"
msgid "21"
msgstr "21"
msgctxt "selection:edi.shipment.in.line.qty,type_:"
msgid "45E"
msgstr "45E"
msgctxt "selection:edi.shipment.in.line.qty,type_:"
msgid "Free Quantity"
msgstr "Cantidad libre"
msgctxt "selection:edi.shipment.in.line.qty,type_:"
msgid "Quantity Sended"
msgstr "Cantidad enviada"
msgctxt "selection:edi.shipment.in.line.qty,type_:"
msgid "Quantity on package"
msgstr "Cantidad en el paquete"
msgctxt "selection:edi.shipment.in.line.qty,unit:"
msgid "EA"
msgstr "EA"
msgctxt "selection:edi.shipment.in.line.qty,unit:"
msgid "Gramo"
msgstr "Gramo"
msgctxt "selection:edi.shipment.in.line.qty,unit:"
msgid "Kilogramo"
msgstr "Kilogramo"
msgctxt "selection:edi.shipment.in.line.qty,unit:"
msgid "Litro"
msgstr "Litro"
msgctxt "selection:edi.shipment.in.line.qty,unit:"
msgid "Pieza"
msgstr "Pieza"
msgctxt "selection:edi.shipment.in.reference,type_:"
msgid "Line Number"
msgstr "Número de línea"
msgctxt "selection:edi.shipment.in.reference,type_:"
msgid "Purchase"
msgstr "Compra"
msgctxt "selection:edi.shipment.in.reference,type_:"
msgid "Shipment"
msgstr "Albarán"
msgctxt "selection:edi.shipment.in.reference,type_:"
msgid "VN"
msgstr "VN"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Endorser"
msgstr "Probador"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Final Receiver"
msgstr " Receptor final"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Invoice Issuer"
msgstr " Emisor de facturas"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Invoice Receiver"
msgstr " Receptor de facturas"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Legal Purchaser"
msgstr "Comprador legal"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Legal Supplier"
msgstr " Proveedor legal"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "NAD"
msgstr ""
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "NADMR"
msgstr ""
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "NADPE"
msgstr ""
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "NADPW"
msgstr ""
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Payment Issuer"
msgstr " Emisor de pago"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Purchaser"
msgstr "Comprador"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Sender"
msgstr ""
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Stock Receiver"
msgstr " Receptor de stock"
msgctxt "selection:edi.shipment.supplier,type_:"
msgid "Supplier"
msgstr "Proveedor"
msgctxt "selection:ir.cron,method:"
msgid "Import EDI Shipment In Orders"
msgstr "Importar pedidos albarán de proveedor EDI"
msgctxt "view:edi.shipment.in:"
msgid "Create Shipment"
msgstr "Crear albarán"
msgctxt "view:edi.shipment.in:"
msgid "Lines"
msgstr "Líneas"
msgctxt "view:edi.shipment.in:"
msgid "Parties"
msgstr "Terceros"
msgctxt "view:edi.shipment.in:"
msgid "Search References"
msgstr " Buscar referencias"
msgctxt "view:stock.configuration:"
msgid "EDI"

16
message.xml Normal file
View file

@ -0,0 +1,16 @@
<?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_no_move_ref">
<field name="text">There is not move reference in line number %(number)s.</field>
</record>
<record model="ir.message" id="msg_no_purchase_ref">
<field name="text">There is not purchase origin in edi shipment references.</field>
</record>
<record model="ir.message" id="msg_no_product">
<field name="text">There is not product in line number %(number)s.</field>
</record>
</data>
</tryton>

View file

@ -15,10 +15,6 @@ from edifact.utils import (with_segment_check, validate_segment,
from datetime import datetime
import logging
__all__ = ['Move', 'StockConfiguration', 'ShipmentIn', 'Cron']
logger = logging.getLogger('stock_shipment_in_edi')
DEFAULT_FILES_LOCATION = '/tmp/'
@ -27,30 +23,8 @@ DEFAULT_TEMPLATE = 'DESADV_ediversa.yml'
KNOWN_EXTENSIONS = ['.txt', '.edi', '.pla']
class Cron(metaclass=PoolMeta):
__name__ = 'ir.cron'
@classmethod
def __setup__(cls):
super(Cron, cls).__setup__()
cls.method.selection.extend([
('stock.shipment.in|get_edi_shipments_cron',
'Import EDI Shipment In Orders')])
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
edi_quantity = fields.Float('EDI Quantity',
digits=(16, Eval('unit_digits', 2)),
states=MOVE_STATES, depends=['state', 'unit_digits'])
edi_description = fields.Text('EDI Description', size=None)
@classmethod
def copy(cls, records, default=None):
default = default.copy() if default else {}
default.setdefault('edi_quantity')
default.setdefault('edi_description')
return super(Move, cls).copy(records, default=default)
def _get_new_lot(self, values, expiration):
pool = Pool()
@ -66,312 +40,3 @@ class Move(metaclass=PoolMeta):
else:
lot.on_change_product()
return lot
class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
__name__ = 'stock.shipment.in'
@classmethod
def import_edi_input(cls, response, template):
pool = Pool()
ProductCode = pool.get('product.code')
Template = pool.get('product.template')
Move = pool.get('stock.move')
Lot = pool.get('stock.lot')
default_values = cls.default_get(cls._fields.keys(),
with_rec_name=False)
move_default_values = Move.default_get(Move._fields.keys(),
with_rec_name=False)
def get_new_move():
if product:
move = Move(**move_default_values)
move.product = product
move.on_change_product()
move.quantity = quantity
if values.get('unit'):
move.uom = values.get('unit')
move.state = 'draft'
move.currency = purchase.currency
move.planned_date = shipment.planned_date
move.unit_price = product.list_price
move.edi_description = values.get('description')
move.shipment = shipment
if (quantity or 0) >= 0:
move.from_location = purchase.party.supplier_location.id
elif purchase.return_from_location:
move.from_location = purchase.return_from_location.id
if (quantity or 0) >= 0:
if purchase.warehouse:
move.to_location = purchase.warehouse.input_location.id
else:
move.to_location = purchase.party.supplier_location.id
return move
total_errors = []
control_chars = cls.set_control_chars(
template.get('control_chars', {}))
message = Message.from_str(response.upper().replace('\r', ''),
characters=control_chars)
segments_iterator = RewindIterator(message.segments)
template_header = template.get('header', {})
template_detail = template.get('detail', {})
detail = [x for x in separate_section(segments_iterator, start='CPS')]
del(segments_iterator)
# If there isn't a segment DESADV_D_96A_UN_EAN005
# means the file readed it's not a order response.
if not message.get_segment('DESADV_D_96A_UN_EAN005'):
logger.error("File %s processed is not shipment with header: "
"DESADV_D_96A_UN_EAN005")
return DO_NOTHING, NO_ERRORS
rffs = message.get_segments('RFF')
rff, = [x for x in rffs if x.elements[0] == 'ON'] or [None]
template_rff = template_header.get('RFF')
purchase, errors = cls._process_RFF(rff, template_rff, control_chars)
if errors:
total_errors += errors
if not purchase:
return None, total_errors
if purchase and purchase.shipments:
logger.error("Purchase has a shipment, do not search for reference"
"on shipment")
return DO_NOTHING, NO_ERRORS
shipment = cls(**default_values)
shipment.supplier = purchase.party
shipment.on_change_supplier()
shipment.warehouse = purchase.warehouse
shipment.moves = purchase.pending_moves
dtm = message.get_segment('DTM')
template_dtm = template_header.get('DTM')
effective_date, planned_date, errors = cls._process_DTM(dtm,
template_dtm, control_chars)
if errors:
total_errors += errors
shipment.effective_date = effective_date
shipment.planned_date = planned_date
bgm = message.get_segment('BGM')
template_bgm = template_header.get('BGM')
reference, errors = cls._process_BGM(bgm, template_bgm,
control_chars)
if errors:
total_errors += errors
shipment.reference = reference
del(template_header)
shipment.save()
scannable_codes = ProductCode.search([
('product', 'in', shipment.scannable_products)
])
scannable_products = {pc.number: pc.product for pc in scannable_codes}
to_save = []
for cps_group in detail:
segments_iterator = RewindIterator(cps_group)
linegroups = [x for x in separate_section(segments_iterator,
start='LIN')]
for linegroup in linegroups:
values = {}
for segment in linegroup:
if segment.tag not in list(template_detail.keys()):
continue
template_segment = template_detail.get(segment.tag)
tag = (segment.tag if segment.tag.endswith('LIN') else
'{}LIN'.format(segment.tag))
process = eval('cls._process_{}'.format(tag))
to_update, errors = process(segment, template_segment)
if errors:
# If there are errors the linegroup isn't processed
break
if to_update:
values.update(to_update)
if errors:
total_errors += errors
continue
product = scannable_products.get(values.get('product'))
quantity = values.get('quantity')
if not quantity:
continue
matching_moves = None
if product:
matching_moves = [m for m in shipment.pending_moves if
(m.product == product) and (m.pending_quantity > 0)]
if matching_moves:
move = matching_moves[0]
else:
move = get_new_move()
else:
product_code, = ProductCode.search([
('number', '=', values.get('product'))
], limit=1) or [None]
if not product_code:
continue
product = product_code.product
move = get_new_move()
if not move:
continue
move.edi_quantity = quantity
move.edi_description = values.get('description')
if hasattr(Template, 'lot_required') and product.lot_required:
expiration = None
if hasattr(Template, 'expiration_state'):
expiration = product.expiration_state
lots = Lot.search([
('number', '=', values.get('lot')),
('product', '=', move.product)
], limit=1)
if lots:
lot, = lots
if ((not expiration or expiration != 'none')
and values.get('expiration_date', False)):
expiration_date = values.get('expiration_date')
if expiration_date and lot.expiration_date:
if expiration_date < lot.expiration_date:
lot.expiration_date = expiration_date
else:
lot = move._get_new_lot(values, expiration)
if lot:
lot.save()
move.lot = lot
to_save.append(move)
if to_save:
Move.save(to_save)
return shipment, total_errors
@classmethod
@with_segment_check
def _process_RFF(cls, segment, template_segment, control_chars=None):
pool = Pool()
Purchase = pool.get('purchase.purchase')
Config = pool.get('purchase.configuration')
purchase_num = segment.elements[1]
padding = (Config(1).purchase_sequence and
Config(1).purchase_sequence.padding - len(purchase_num))
if padding:
purchase_num = "0"*padding + purchase_num
purchase, = Purchase.search([
('number', '=', purchase_num),
('state', 'in', ('processing', 'done'))
], limit=1) or [None]
if not purchase:
purchases = Purchase.search([
('reference', '=', purchase_num),
('state', 'in', ('processing', 'done'))
])
if len(purchases) == 1:
purchase = purchases[0]
if not purchase:
error_msg = 'Purchase number {} not found'.format(purchase_num)
serialized_segment = Serializer(control_chars).serialize([segment])
return DO_NOTHING, ['{}: {}'.format(error_msg, serialized_segment)]
return purchase, NO_ERRORS
@classmethod
@with_segment_check
def _process_DTM(cls, segment, template, control_chars=None):
effective_date = cls.get_datetime_obj_from_edi_date(
segment.elements[0])
planned_date = (cls.get_datetime_obj_from_edi_date(
segment.elements[1]) if len(segment.elements) > 1 else None)
return effective_date, planned_date, NO_ERRORS
@classmethod
@with_segment_check
def _process_BGM(cls, segment, template, control_chars=None):
return segment.elements[0], NO_ERRORS
@classmethod
@with_segment_check
def _process_LIN(cls, segment, template):
return {'product': segment.elements[0]}, NO_ERRORS
@classmethod
@with_segment_check
def _process_QTYLIN(cls, segment, template):
pool = Pool()
Uom = pool.get('product.uom')
result = {}
qualifier = segment.elements[0]
if qualifier != '12':
return DO_NOTHING, NO_ERRORS
if len(segment.elements) > 2:
uom_value = UOMS_EDI_TO_TRYTON.get(segment.elements[2], 'u')
else:
uom_value = 'u'
uom, = Uom.search([('symbol', '=', uom_value)], limit=1)
result['unit'] = uom
quantity = float(segment.elements[1])
result['quantity'] = quantity
return result, NO_ERRORS
@classmethod
@with_segment_check
def _process_IMDLIN(cls, segment, template):
description = segment.elements[1] or None
return {'description': description}, NO_ERRORS
@classmethod
@with_segment_check
def _process_PCILIN(cls, segment, template):
elements_lenght = len(segment.elements)
expiration_date = (cls.get_datetime_obj_from_edi_date(
segment.elements[1]) if elements_lenght > 1 else None)
lot = segment.elements[7] if elements_lenght > 6 else None
result = {
'expiration_date': (expiration_date.date() if expiration_date
else None),
'lot': lot
}
return result, NO_ERRORS
@classmethod
def _process_CPSLIN(cls, segment, template):
return DO_NOTHING, NO_ERRORS
@classmethod
def create_edi_shipments(cls):
pool = Pool()
Configuration = pool.get('stock.configuration')
configuration = Configuration(1)
source_path = os.path.abspath(configuration.inbox_path_edi or
DEFAULT_FILES_LOCATION)
errors_path = os.path.abspath(configuration.errors_path_edi
or DEFAULT_FILES_LOCATION)
template_name = (configuration.template_order_response_edi
or DEFAULT_TEMPLATE)
template_path = os.path.join(os.path.join(MODULE_PATH, 'templates'),
template_name)
template = EdiTemplate(template_name, template_path)
return cls.process_edi_inputs(source_path, errors_path, template)
@classmethod
def get_edi_shipments_cron(cls):
cls.create_edi_shipments()
return True
class StockConfiguration(metaclass=PoolMeta):
__name__ = 'stock.configuration'
inbox_path_edi = fields.Char('Inbox Path EDI')
errors_path_edi = fields.Char('Errors Path')
template_order_response_edi = fields.Char('Template EDI Used for Response')

View file

@ -3,16 +3,6 @@
copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="move_view_form_pending">
<field name="model">stock.move</field>
<field name="inherit" ref="stock_scanner.move_view_form_pending"/>
<field name="name">move_form_pending</field>
</record>
<record model="ir.ui.view" id="move_view_tree_pending">
<field name="model">stock.move</field>
<field name="inherit" ref="stock_scanner.move_view_tree_pending"/>
<field name="name">move_tree_pending</field>
</record>
<record model="ir.ui.view" id="stock_configuration_view_form">
<field name="model">stock.configuration</field>
<field name="inherit" ref="stock.stock_configuration_view_form"/>
@ -30,12 +20,5 @@
<field name="user" ref="user_edi_shipment_in"/>
<field name="group" ref="res.group_admin"/>
</record>
<!-- Edi Shipments cron -->
<record model="ir.cron" id="cron_import_edi_shipment_in">
<field name="active" eval="False"/>
<field name="interval_number" eval="1"/>
<field name="interval_type">days</field>
<field name="method">stock.shipment.in|get_edi_shipments_cron</field>
</record>
</data>
</tryton>

View file

@ -9,5 +9,6 @@ extras_depend:
stock_lot
stock_lot_sled
xml:
shipment.xml
edi_shipment.xml
message.xml
shipment.xml

View file

@ -1,13 +0,0 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='pending_quantity']" position="after">
<label name="edi_quantity"/>
<field name="edi_quantity"/>
<newline/>
<label name="edi_description"/>
<newline/>
<field name="edi_description" colspan="4"/>
</xpath>
</data>

View file

@ -1,9 +0,0 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/tree/field[@name='pending_quantity']" position="after">
<field name="edi_quantity"/>
<field name="edi_description"/>
</xpath>
</data>

View file

@ -8,11 +8,5 @@
<label name="inbox_path_edi"/>
<field name="inbox_path_edi" colspan="3"/>
<newline/>
<label name="errors_path_edi"/>
<field name="errors_path_edi" colspan="3"/>
<newline/>
<label name="template_order_response_edi"/>
<field name="template_order_response_edi" colspan="3"/>
<newline/>
</xpath>
</data>