fix desadv

This commit is contained in:
Marcos Sabater 2021-05-26 16:29:55 +02:00
parent ae089e5867
commit 681ffcb1e9
4 changed files with 17 additions and 21 deletions

View File

@ -15,8 +15,6 @@ from datetime import datetime
from trytond.exceptions import UserError
__all__ = ['Move', 'StockConfiguration', 'ShipmentIn', 'Cron']
DEFAULT_FILES_LOCATION = '/tmp/'
MODULE_PATH = os.path.dirname(os.path.abspath(__file__))
DEFAULT_TEMPLATE = 'DESADV_ediversa.yml'
@ -99,10 +97,11 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
# 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'):
unh = message.get_segment('UNH')
if not unh or unh.elements[1][0] != 'DESADV':
return DO_NOTHING, NO_ERRORS
rffs = message.get_segments('RFF')
rff, = [x for x in rffs if x.elements[0] == 'ON'] or [None]
rff, = [x for x in rffs if x.elements[0][0] == 'ON'] or [None]
template_rff = template_header.get('RFF')
purchase, errors = cls._process_RFF(rff, template_rff, control_chars)
if errors:
@ -114,7 +113,7 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
shipment.supplier = purchase.party
shipment.on_change_supplier()
shipment.warehouse = purchase.warehouse
shipment.moves = purchase.pending_moves
shipment.moves = [m for m in purchase.moves if not m.shipment]
dtm = message.get_segment('DTM')
template_dtm = template_header.get('DTM')
@ -138,7 +137,7 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
shipment.save()
scannable_codes = ProductCode.search([
('product', 'in', shipment.scannable_products)
('product', 'in', [l.product.id for l in shipment.moves])
])
scannable_products = {pc.number: pc.product for pc in scannable_codes}
to_save = []
@ -216,14 +215,13 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
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')
purchase_num = segment.elements[1]
purchase_num = segment.elements[0][2]
purchase, = Purchase.search([
('number', '=', purchase_num),
('state', 'in', ('processing', 'done'))
('state', 'in', ['processing', 'done'])
], limit=1) or [None]
if not purchase:
error_msg = 'Purchase number {} not found'.format(purchase_num)
@ -235,7 +233,7 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
@with_segment_check
def _process_DTM(cls, segment, template, control_chars=None):
effective_date = cls.get_datetime_obj_from_edi_date(
segment.elements[0])
segment.elements[0][2])
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
@ -246,7 +244,6 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
return segment.elements[0], NO_ERRORS
@classmethod
@with_segment_check
def _process_LIN(cls, segment, template):
return {'product': segment.elements[0]}, NO_ERRORS

View File

@ -3,16 +3,16 @@
copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="move_view_form_pending">
<!--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">
</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-->
<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"/>
@ -31,11 +31,11 @@
<field name="group" ref="res.group_admin"/>
</record>
<!-- Edi Shipments cron -->
<record model="ir.cron" id="cron_import_edi_shipment_in">
<!--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>
</record-->
</data>
</tryton>

View File

@ -2,10 +2,10 @@ control_chars:
data_separator: '|'
segment_terminator: "\n"
header:
DESADV_D_96A_UN_EAN005: []
UNH_1_DESADV: []
BGM: ['!value', '351', !!python/tuple ['9', '31']]
DTM: ['!value']
RFF: [!!python/tuple ['ON', 'DQ'], '!value']
RFF: [!!python/tuple ['ON', 'DQ', 'AAJ'], '!value']
detail:
CPS: ['!value', !!python/tuple ['', '!value']]
LIN: ['!value', 'EN', '!value']

View File

@ -2,9 +2,8 @@
version=5.2.0
depends:
edocument_unedifact
party_edi
product_barcode
stock_scanner
party_edi
extras_depend:
stock_lot
xml: