Improved packing exception handling
This commit is contained in:
1 parent
b911b44eb5
commit
0e5d73dfa9
2 files changed
+25
-55
No files matched your search
@@ -894,10 +894,10 @@ class SaleLine(OSV):
|
||||
moves = fields.One2Many('stock.move', 'sale_line', 'Moves',
|
||||
readonly=True, select=1)
|
||||
moves_ignored = fields.Many2Many('stock.move', 'sale_line_moves_ignored_rel',
|
||||
'sale_line', 'move', 'Moves Ignored', readonly=True)
|
||||
moves_duplicated = fields.Many2Many('stock.move',
|
||||
'sale_line_moves_duplicated_rel', 'sale_line', 'move',
|
||||
'Moves Duplicated', readonly=True)
|
||||
'sale_line', 'move', 'Ignored Moves', readonly=True)
|
||||
moves_recreated = fields.Many2Many('stock.move',
|
||||
'sale_line_moves_recreated_rel', 'sale_line', 'move',
|
||||
'Recreated Moves', readonly=True)
|
||||
move_done = fields.Function('get_move_done', type='boolean',
|
||||
string='Moves Done')
|
||||
move_exception = fields.Function('get_move_exception', type='boolean',
|
||||
@@ -961,7 +961,7 @@ class SaleLine(OSV):
|
||||
res[line.id] = True
|
||||
continue
|
||||
skip_ids = set(x.id for x in line.moves_ignored)
|
||||
skip_ids.update(x.id for x in line.moves_duplicated)
|
||||
skip_ids.update(x.id for x in line.moves_recreated)
|
||||
quantity = line.quantity
|
||||
for move in line.moves:
|
||||
if move.state != 'done' \
|
||||
@@ -981,7 +981,7 @@ class SaleLine(OSV):
|
||||
for line in self.browse(cursor, user, ids, context=context):
|
||||
val = False
|
||||
skip_ids = set(x.id for x in line.moves_ignored)
|
||||
skip_ids.update(x.id for x in line.moves_duplicated)
|
||||
skip_ids.update(x.id for x in line.moves_recreated)
|
||||
for move in line.moves:
|
||||
if move.state == 'cancel' \
|
||||
and move.id not in skip_ids:
|
||||
@@ -1176,7 +1176,7 @@ class SaleLine(OSV):
|
||||
default = default.copy()
|
||||
default['moves'] = False
|
||||
default['moves_ignored'] = False
|
||||
default['moves_duplicated'] = False
|
||||
default['moves_recreated'] = False
|
||||
default['invoice_lines'] = False
|
||||
return super(SaleLine, self).copy(cursor, user, ids,
|
||||
default=default, context=context)
|
||||
@@ -1201,7 +1201,7 @@ class SaleLine(OSV):
|
||||
return
|
||||
if line.product.type == 'service':
|
||||
return
|
||||
skip_ids = set(x.id for x in line.moves_duplicated)
|
||||
skip_ids = set(x.id for x in line.moves_recreated)
|
||||
quantity = line.quantity
|
||||
for move in line.moves:
|
||||
if move.id not in skip_ids:
|
||||
@@ -1398,7 +1398,7 @@ class Move(OSV):
|
||||
type='selection',
|
||||
selection=[('', ''),
|
||||
('ignored', 'Ignored'),
|
||||
('duplicated', 'Duplicated')],
|
||||
('recreated', 'Recreated')],
|
||||
string='Exception State')
|
||||
|
||||
def get_sale(self, cursor, user, ids, name, arg, context=None):
|
||||
@@ -1426,8 +1426,8 @@ class Move(OSV):
|
||||
for move in self.browse(cursor, user, ids, context=context):
|
||||
if not move.sale_line:
|
||||
continue
|
||||
if move.id in (x.id for x in move.sale_line.moves_duplicated):
|
||||
res[move.id] = 'duplicated'
|
||||
if move.id in (x.id for x in move.sale_line.moves_recreated):
|
||||
res[move.id] = 'recreated'
|
||||
if move.id in (x.id for x in move.sale_line.moves_ignored):
|
||||
res[move.id] = 'ignored'
|
||||
return res
|
||||
@@ -1528,13 +1528,13 @@ class HandlePackingExceptionAsk(WizardOSV):
|
||||
_name = 'sale.handle.packing.exception.ask'
|
||||
_description = __doc__
|
||||
|
||||
duplicate_moves = fields.Many2Many(
|
||||
'stock.move', None, None, None, 'Duplicate Moves',
|
||||
recreate_moves = fields.Many2Many(
|
||||
'stock.move', None, None, None, 'Recreate Moves',
|
||||
domain="[('id', 'in', domain_moves)]", depends=['domain_moves'])
|
||||
domain_moves = fields.Many2Many(
|
||||
'stock.move', None, None, None, 'Domain Moves')
|
||||
|
||||
def default_duplicate_moves(self, cursor, user, context=None):
|
||||
def default_recreate_moves(self, cursor, user, context=None):
|
||||
return self.default_domain_moves(cursor, user, context=context)
|
||||
|
||||
def default_domain_moves(self, cursor, user, context=None):
|
||||
@@ -1551,7 +1551,7 @@ class HandlePackingExceptionAsk(WizardOSV):
|
||||
domain_moves = []
|
||||
for line in lines:
|
||||
skip_ids = set(x.id for x in line.moves_ignored)
|
||||
skip_ids.update(x.id for x in line.moves_duplicated)
|
||||
skip_ids.update(x.id for x in line.moves_recreated)
|
||||
for move in line.moves:
|
||||
if move.state == 'cancel' and move.id not in skip_ids:
|
||||
domain_moves.append(move.id)
|
||||
@@ -1589,57 +1589,30 @@ class HandlePackingException(Wizard):
|
||||
sale_line_obj = self.pool.get('sale.line')
|
||||
move_obj = self.pool.get('stock.move')
|
||||
packing_obj = self.pool.get('stock.packing.out')
|
||||
to_duplicate = data['form']['duplicate_moves'][0][1]
|
||||
to_recreate = data['form']['recreate_moves'][0][1]
|
||||
domain_moves = data['form']['domain_moves'][0][1]
|
||||
|
||||
sale = sale_obj.browse(cursor, user, data['id'], context=context)
|
||||
|
||||
duplicate_all = []
|
||||
for line in sale.lines:
|
||||
moves_ignored = []
|
||||
moves_duplicated = []
|
||||
moves_recreated = []
|
||||
skip_ids = set(x.id for x in line.moves_ignored)
|
||||
skip_ids.update(x.id for x in line.moves_duplicated)
|
||||
skip_ids.update(x.id for x in line.moves_recreated)
|
||||
for move in line.moves:
|
||||
if move.id not in domain_moves or move.id in skip_ids:
|
||||
continue
|
||||
if move.id in to_duplicate:
|
||||
moves_duplicated.append(move.id)
|
||||
if move.id in to_recreate:
|
||||
moves_recreated.append(move.id)
|
||||
else:
|
||||
moves_ignored.append(move.id)
|
||||
|
||||
duplicate_all.extend(moves_duplicated)
|
||||
sale_line_obj.write(
|
||||
cursor, user, line.id,
|
||||
{'moves_ignored': [('add', moves_ignored)],
|
||||
'moves_duplicated': [('add', moves_duplicated)]},
|
||||
'moves_recreated': [('add', moves_recreated)]},
|
||||
context=context)
|
||||
|
||||
if duplicate_all:
|
||||
ctx = context and context.copy() or {}
|
||||
ctx['user'] = user
|
||||
packing_id = packing_obj.create(
|
||||
cursor, 0,
|
||||
{'planned_date': sale.sale_date,
|
||||
'customer': sale.party.id,
|
||||
'delivery_address': sale.packing_address.id,
|
||||
'reference': sale.reference,
|
||||
'warehouse': sale.warehouse.id,},
|
||||
context=ctx)
|
||||
default = {
|
||||
'state': 'draft',
|
||||
'packing_in': False,
|
||||
'packing_out': packing_id,
|
||||
'packing_in_return': False,
|
||||
'packing_out_return': False,
|
||||
'packing_internal': False,
|
||||
}
|
||||
move_obj.copy(
|
||||
cursor, user, duplicate_all, default=default, context=context)
|
||||
|
||||
packing_obj.workflow_trigger_validate(cursor, 0, packing_id,
|
||||
'waiting', context=ctx)
|
||||
|
||||
sale_obj.workflow_trigger_validate(cursor, user, data['id'],
|
||||
'packing_ok', context=context)
|
||||
|
||||
|
||||
@@ -183,20 +183,17 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Handle packing Exception" col="2">
|
||||
<image name="tryton-dialog-information"/>
|
||||
<group col="1" colspan="1" id="moves">
|
||||
<separator string="Choose move to duplicate"
|
||||
<form string="Handle packing Exception" col="1">
|
||||
<separator string="Choose move to recreate"
|
||||
id="choose"/>
|
||||
<field name="duplicate_moves">
|
||||
<tree string="Duplicate Moves" fill="1">
|
||||
<field name="recreate_moves">
|
||||
<tree string="Recreate Moves" fill="1">
|
||||
<field name="product"/>
|
||||
<field name="quantity"/>
|
||||
<field name="uom"/>
|
||||
<field name="unit_digits" tree_invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
|
||||
Reference in new issue
Block a user