Added extra fields

This commit is contained in:
Marcos Sabater 2021-11-16 22:56:57 +01:00
parent 53fbbc9ca9
commit 2aed9905f4
6 changed files with 116 additions and 15 deletions

View File

@ -10,6 +10,10 @@ msgctxt "field:stock.configuration,inbox_path_edi:"
msgid "Inbox Path EDI"
msgstr "Path de entrada EDI"
msgctxt "field:stock.shipment.in,despatch_date:"
msgid "Despatch Date"
msgstr "Fecha de envío"
msgctxt "field:stock.configuration,template_order_response_edi:"
msgid "Template EDI Used for Response"
msgstr "Plantilla EDI usada para la Respuesta"

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

@ -50,6 +50,18 @@ class Move(metaclass=PoolMeta):
class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
__name__ = 'stock.shipment.in'
despatch_date = fields.Date('Despatch Date',
states={
'readonly': Eval('state').in_(['cancel', 'done']),
},
depends=['state'])
#TODO remove field if purchase_shipment_cost is ever installed
carrier = fields.Many2One('carrier', 'Carrier', states={
'readonly': Eval('state') != 'draft',
},
depends=['state'])
@classmethod
def import_edi_input(cls, response, template):
@ -120,8 +132,9 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
unh = message.get_segment('UNH')
if not unh or unh.elements[1][0] != 'DESADV':
return DO_NOTHING, NO_ERRORS
rffs = message.get_segments('RFF')
rffs = [x for x in message.get_segments('RFF')]
rff, = [x for x in rffs if x.elements[0][0] == 'ON'] or [None]
reference, = [x for x in rffs if x.elements[0][0] == 'DQ'] or [None]
template_rff = template_header.get('RFF')
purchase, errors = cls._process_RFF(rff, template_rff, control_chars)
if errors:
@ -133,16 +146,19 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
shipment.supplier = purchase.party
shipment.on_change_supplier()
shipment.warehouse = purchase.warehouse
shipment.reference = reference.elements[0][2] if reference else None
shipment.moves = [m for m in purchase.moves if not m.shipment]
dtm = message.get_segment('DTM')
dtms = [d for d in message.get_segments('DTM')]
template_dtm = template_header.get('DTM')
effective_date, planned_date, errors = cls._process_DTM(dtm,
effective_date, planned_date, despatch_date, errors = cls._process_DTMs(dtms,
template_dtm, control_chars)
if errors:
total_errors += errors
shipment.effective_date = effective_date
shipment.planned_date = planned_date
if despatch_date:
shipment.despatch_date = despatch_date
bgm = message.get_segment('BGM')
template_bgm = template_header.get('BGM')
@ -152,6 +168,15 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
total_errors += errors
shipment.reference = reference
tdt = message.get_segment('TDT')
if tdt:
template_tdt = template_header.get('TDT')
carrier, errors = cls._process_TDT(tdt, template_tdt,
control_chars)
shipment.carrier = carrier
if errors:
total_errors += errors
del(template_header)
shipment.save()
@ -168,7 +193,7 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
for linegroup in linegroups:
values = {}
for segment in linegroup:
if segment.tag not in list(template_detail.keys()):
if segment.tag not in [x[0:3] for x in template_detail.keys()]:
continue
template_segment = template_detail.get(segment.tag)
tag = (segment.tag if segment.tag.endswith('LIN') else
@ -189,8 +214,8 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
quantity = values.get('quantity')
matching_moves = None
if product:
matching_moves = [m for m in shipment.pending_moves if
(m.product == product) and (m.pending_quantity > 0)]
matching_moves = [
m for m in shipment.moves if m.product == product]
if matching_moves:
move = matching_moves[0]
else:
@ -203,8 +228,12 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
continue
product = product_code.product
move = get_new_move()
move.quantity = quantity
move.edi_quantity = quantity
move.edi_description = values.get('description')
move_amount = values.get('amount', None)
if move_amount:
move.unit_price = move_amount / quantity
manage_lots()
to_save.append(move)
@ -232,6 +261,38 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
return DO_NOTHING, ['{}: {}'.format(error_msg, serialized_segment)]
return purchase, NO_ERRORS
@classmethod
def _process_TDT(cls, segment, template_segment, control_chars=None):
pool = Pool()
Identifier = pool.get('party.identifier')
Carrier = pool.get('carrier')
carrier_ean = segment.elements[6]
identifiers = Identifier.search([
('type', '=', 'EDI_supplier'),
('code', '=', carrier_ean)
])
if identifiers:
party = identifiers[0].party
carriers = Carrier.search([('party', '=', party)])
return carriers[0], NO_ERRORS
return {}, NO_ERRORS
@classmethod
def _process_DTMs(cls, segments, template, control_chars=None):
despatch_date = None
for segment in segments:
date_type = segment.elements[0][0]
if date_type == '137':
effective_date = cls.get_datetime_obj_from_edi_date(
segment.elements[0][2])
elif date_type == '191':
planned_date = (cls.get_datetime_obj_from_edi_date(
segment.elements[0][2]))
elif date_type == '11':
despatch_date = (cls.get_datetime_obj_from_edi_date(
segment.elements[0][2]))
return effective_date, planned_date, despatch_date, NO_ERRORS
@classmethod
@with_segment_check
def _process_DTM(cls, segment, template, control_chars=None):
@ -247,29 +308,31 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
@classmethod
def _process_LIN(cls, segment, template):
return {'product': segment.elements[0]}, NO_ERRORS
return {'product': segment.elements[2][0]}, NO_ERRORS
@classmethod
def _process_MOALIN(cls, segment, template):
return {'amount': float(segment.elements[0][2])}, NO_ERRORS
@classmethod
@with_segment_check
def _process_QTYLIN(cls, segment, template):
pool = Pool()
Uom = pool.get('product.uom')
result = {}
qualifier = segment.elements[0]
qualifier = segment.elements[0][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')
if len(segment.elements[0]) > 2:
uom_value = UOMS_EDI_TO_TRYTON.get(segment.elements[0][2], 'u')
else:
uom_value = 'u'
uom, = Uom.search([('symbol', '=', uom_value)], limit=1)
result['unit'] = uom
quantity = float(segment.elements[1])
quantity = float(segment.elements[0][2])
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

View File

@ -13,6 +13,11 @@
<field name="inherit" ref="stock_scanner.move_view_tree_pending"/>
<field name="name">move_tree_pending</field>
</record-->
<record model="ir.ui.view" id="shipment_in_view_form">
<field name="model">stock.shipment.in</field>
<field name="inherit" ref="stock.shipment_in_view_form"/>
<field name="name">shipment_in_form</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"/>

View File

@ -4,8 +4,10 @@ control_chars:
header:
UNH_1_DESADV: []
BGM: ['!value', '351', !!python/tuple ['9', '31']]
DTM: ['!value']
DTM: [!!python/tuple ['137', '171', '191', '11'], '!value', '102']
RFF: [!!python/tuple ['ON', 'DQ', 'AAJ'], '!value']
TDT: ['!value']
MOA: ['!value']
detail:
CPS: ['!value', !!python/tuple ['', '!value']]
LIN: ['!value', 'EN', '!value']
@ -13,8 +15,8 @@ detail:
IMDLIN: [!!python/tuple ['C', 'F']]
QTYLIN: [!!python/tuple ['12', '59', '192', '21'], '!value']
PCILIN: ['36E']
MOALIN: ['!value', '!value']
#DTMLIN: ['!value']
#MOALIN: ['!value', '!value']
#QVRLIN: ['!value', '21', !!python/tuple ['AA', 'AB', 'AD', 'AS', 'BK', 'BP', 'CP', 'CN', 'PS', 'OS', 'OW', 'TW'], !!python/tuple ['AIT', 'AUE', 'AV', 'AQ', 'IS', 'PC', 'UM', 'VW']]
#PRILIN: [!!python/tuple ['AAA', 'NTP'], '!value', !!python/tuple ['!value', '']]
#RFFLIN: ['LI', '!value']

11
view/shipment_in_form.xml Normal file
View File

@ -0,0 +1,11 @@
<?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='effective_date']" position="after">
<label name="despatch_date"/>
<field name="despatch_date"/>
<label name="carrier"/>
<field name="carrier"/>
</xpath>
</data>