Check all values from key to append move in previous shipment.

This commit is contained in:
Sergio Morillo 2020-04-16 19:11:05 +02:00
parent 5f780dc502
commit c988510e26
5 changed files with 24 additions and 12 deletions

View File

@ -27,5 +27,6 @@ class Configuration(metaclass=PoolMeta):
if table.column_exist('csv_headers'):
table.column_rename('csv_headers', 'shipment_in_csv_headers')
table.drop_column('csv_headers')
super().__register__(module_name)

View File

@ -49,7 +49,7 @@ class ShipmentIn(ShipmentCSVMixin, metaclass=PoolMeta):
@classmethod
def _get_csv_key(cls):
return ('reference', 'supplier', )
return ('supplier', 'reference', )
def _set_csv_move_locations(self, move):
move.from_location = self.on_change_with_supplier_location()

View File

@ -144,12 +144,14 @@ class ShipmentCSVMixin(object):
row[i] = cls._get_csv_field_value(cls, column, row[i],
data=data[_key], row=row)
data[_key][column_no_dot] = row[i]
company = Company(Transaction().context['company'])
for k, v in data.items():
shipment = None
if k[0]:
if any(item for item in k):
old_shipment = None
domain = [('company', '=', company.id), ] + [
domain = [
('company', '=', company.id), ] + [
(k, '=', v.get(k)) for k in cls._get_csv_key()]
shipment = cls.search(domain, limit=1)
if shipment:
@ -157,8 +159,10 @@ class ShipmentCSVMixin(object):
if not shipment:
continue
if v[cls._csv_move_field][0]:
to_del.extend(list(shipment.incoming_moves))
to_del.extend(list(getattr(shipment,
cls._csv_move_field, [])))
else:
# key values are not given so move is from previous record
shipment = old_shipment
if not shipment:
shipment = cls()
@ -187,12 +191,12 @@ class ShipmentCSVMixin(object):
moves.append(move)
if not old_shipment:
shipment.incoming_moves = moves
setattr(shipment, cls._csv_move_field, moves)
shipments.append(shipment)
old_shipment = shipment
else:
shipment.incoming_moves = list(
shipment.incoming_moves) + moves
setattr(shipment, cls._csv_move_field, list(
shipment.incoming_moves) + moves)
if store_file:
model, = Model.search([('model', '=', cls.__name__)])
@ -449,12 +453,18 @@ class StockCsvImport(ModelSQL, ModelView):
__name__ = 'stock.csv_import'
name = fields.Char('Name', required=True)
model = fields.Many2One('ir.model', 'Model', required=True, domain=[
('model', 'in', ['stock.shipment.in', 'stock.shipment.out.return'])])
model = fields.Many2One('ir.model', 'Model', required=True, readonly=True,
domain=[
('model', 'in', [
'stock.shipment.in',
'stock.shipment.out.return',
'stock.shipment.internal'
])
])
date = fields.Function(fields.Date('Date'), 'get_date')
file = fields.Binary('File', required=True, readonly=True,
file_id=file_id, store_prefix=store_prefix)
file_id = fields.Char('File ID', readonly=True)
def get_date(self, name):
return self.create_date
return self.create_date.date()

View File

@ -3,9 +3,11 @@
copyright notices and license terms. -->
<form>
<label name="name"/>
<field name="name"/>
<field name="name" colspan="3"/>
<label name="model"/>
<field name="model"/>
<label name="date"/>
<field name="date"/>
<label name="file"/>
<field name="file"/>
</form>

View File

@ -5,5 +5,4 @@
<field name="name"/>
<field name="model"/>
<field name="date" widget="date"/>
<field name="date" widget="time" string="Time"/>
</tree>