2008-06-23 21:01:22 +02:00
|
|
|
#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
|
2008-04-08 14:27:53 +02:00
|
|
|
"Packing"
|
2008-07-17 19:37:38 +02:00
|
|
|
from trytond.osv import fields, OSV
|
2008-05-08 17:24:49 +02:00
|
|
|
from trytond.netsvc import LocalService
|
2008-05-13 13:10:49 +02:00
|
|
|
import datetime
|
2008-05-16 01:53:15 +02:00
|
|
|
from trytond.report import CompanyReport
|
2008-04-08 14:27:53 +02:00
|
|
|
|
|
|
|
|
STATES = {
|
|
|
|
|
'readonly': "state in ('cancel', 'done')",
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-05 20:24:09 +02:00
|
|
|
|
2008-04-17 02:31:55 +02:00
|
|
|
class PackingIn(OSV):
|
|
|
|
|
"Supplier Packing"
|
|
|
|
|
_name = 'stock.packing.in'
|
2008-04-08 14:27:53 +02:00
|
|
|
_description = __doc__
|
|
|
|
|
_rec_name = 'code'
|
|
|
|
|
|
2008-10-20 17:58:12 +02:00
|
|
|
effective_date = fields.DateTime('Effective Date', readonly=True)
|
2008-05-22 01:10:59 +02:00
|
|
|
planned_date = fields.DateTime(
|
2008-06-11 20:18:37 +02:00
|
|
|
'Planned Date', states={'readonly': "state != 'draft'",})
|
2008-05-22 01:10:59 +02:00
|
|
|
reference = fields.Char(
|
|
|
|
|
"Reference", size=None, select=1,
|
2008-06-11 20:18:37 +02:00
|
|
|
states={'readonly': "state != 'draft'",})
|
2008-05-21 18:14:52 +02:00
|
|
|
supplier = fields.Many2One('relationship.party', 'Supplier',
|
|
|
|
|
states={
|
2008-09-08 19:23:11 +02:00
|
|
|
'readonly': "state != 'draft' or bool(incoming_moves)",
|
|
|
|
|
}, on_change=['supplier'], required=True)
|
2008-05-21 18:14:52 +02:00
|
|
|
contact_address = fields.Many2One('relationship.address', 'Contact Address',
|
|
|
|
|
states={
|
|
|
|
|
'readonly': "state != 'draft'",
|
|
|
|
|
}, domain="[('party', '=', supplier)]")
|
2008-05-07 18:04:25 +02:00
|
|
|
warehouse = fields.Many2One('stock.location', "Warehouse",
|
2008-09-30 17:11:05 +02:00
|
|
|
required=True, domain=[('type', '=', 'warehouse')],
|
2008-09-08 19:23:11 +02:00
|
|
|
states={
|
|
|
|
|
'readonly': "state in ('cancel', 'done') or " \
|
|
|
|
|
"bool(incoming_moves)",
|
|
|
|
|
})
|
2008-05-07 18:04:25 +02:00
|
|
|
incoming_moves = fields.Function('get_incoming_moves', type='one2many',
|
|
|
|
|
relation='stock.move', string='Incoming Moves',
|
2008-07-07 11:37:38 +02:00
|
|
|
fnct_inv='set_incoming_moves', add_remove="[" \
|
|
|
|
|
"('packing_in', '=', False),"\
|
|
|
|
|
"('from_location.type', '=', 'supplier'),"\
|
2008-07-07 15:54:10 +02:00
|
|
|
"('state', '=', 'draft'),"\
|
2008-07-07 11:37:38 +02:00
|
|
|
"('to_location_warehouse', '=', warehouse),"\
|
|
|
|
|
"]",
|
2008-05-07 18:04:25 +02:00
|
|
|
states={
|
2008-07-18 12:41:51 +02:00
|
|
|
'readonly': "state in ('received', 'done', 'cancel')",
|
2008-07-07 15:54:10 +02:00
|
|
|
}, context="{'warehouse': warehouse, 'type': 'incoming'}")
|
2008-05-07 18:04:25 +02:00
|
|
|
inventory_moves = fields.Function('get_inventory_moves', type='one2many',
|
|
|
|
|
relation='stock.move', string='Inventory Moves',
|
|
|
|
|
fnct_inv='set_inventory_moves',
|
|
|
|
|
states={
|
2008-07-18 12:41:51 +02:00
|
|
|
'readonly': "state in ('draft', 'done', 'cancel')",
|
2008-07-07 15:54:10 +02:00
|
|
|
}, context="{'warehouse': warehouse, 'type':'inventory_in'}")
|
2008-05-07 18:04:25 +02:00
|
|
|
moves = fields.One2Many('stock.move', 'packing_in', 'Moves',
|
|
|
|
|
readonly=True)
|
2008-05-07 19:01:29 +02:00
|
|
|
code = fields.Char("Code", size=None, select=1, readonly=True)
|
2008-05-07 18:04:25 +02:00
|
|
|
state = fields.Selection([
|
|
|
|
|
('draft', 'Draft'),
|
|
|
|
|
('done', 'Done'),
|
|
|
|
|
('cancel', 'Cancel'),
|
|
|
|
|
('received', 'Received'),
|
|
|
|
|
], 'State', readonly=True)
|
2008-04-08 14:27:53 +02:00
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(PackingIn, self).__init__()
|
|
|
|
|
self._rpc_allowed += [
|
2008-05-08 17:24:49 +02:00
|
|
|
'button_draft',
|
|
|
|
|
]
|
2008-04-22 17:49:50 +02:00
|
|
|
self._order[0] = ('id', 'DESC')
|
2008-07-17 19:37:38 +02:00
|
|
|
self._error_messages.update({
|
|
|
|
|
'incoming_move_input_dest': 'Incoming Moves must ' \
|
|
|
|
|
'have input location as destination location!',
|
|
|
|
|
'inventory_move_input_source': 'Inventory Moves must ' \
|
|
|
|
|
'have input location as source location!',
|
|
|
|
|
'outgoing_move_output_source': 'Outgoing Moves must ' \
|
|
|
|
|
'have output location as source location!',
|
|
|
|
|
'inventory_move_output_dest': 'Inventory Moves must ' \
|
|
|
|
|
'have output location as destination location!',
|
|
|
|
|
})
|
2008-04-08 14:27:53 +02:00
|
|
|
|
|
|
|
|
def default_state(self, cursor, user, context=None):
|
|
|
|
|
return 'draft'
|
|
|
|
|
|
2008-05-20 22:28:32 +02:00
|
|
|
def on_change_supplier(self, cursor, user, ids, values, context=None):
|
|
|
|
|
if not values.get('supplier'):
|
|
|
|
|
return {}
|
2008-05-21 18:14:52 +02:00
|
|
|
party_obj = self.pool.get("relationship.party")
|
|
|
|
|
address_id = party_obj.address_get(cursor, user, values['supplier'],
|
2008-05-20 22:28:32 +02:00
|
|
|
context=context)
|
|
|
|
|
return {'contact_address': address_id}
|
|
|
|
|
|
2008-05-07 18:04:25 +02:00
|
|
|
def get_incoming_moves(self, cursor, user, ids, name, arg, context=None):
|
|
|
|
|
res = {}
|
|
|
|
|
for packing in self.browse(cursor, user, ids, context=context):
|
|
|
|
|
res[packing.id] = []
|
|
|
|
|
for move in packing.moves:
|
|
|
|
|
if move.to_location.id == packing.warehouse.input_location.id:
|
|
|
|
|
res[packing.id].append(move.id)
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
def set_incoming_moves(self, cursor, user, packing_id, name, value, arg,
|
|
|
|
|
context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
for act in value:
|
|
|
|
|
if act[0] == 'create':
|
|
|
|
|
if 'to_location' in act[1]:
|
|
|
|
|
if act[1]['to_location'] != \
|
|
|
|
|
packing.warehouse.input_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'incoming_move_input_dest', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'write':
|
|
|
|
|
if 'to_location' in act[2]:
|
|
|
|
|
if act[2]['to_location'] != \
|
|
|
|
|
packing.warehouse.input_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'incoming_move_input_dest', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'add':
|
|
|
|
|
move = move_obj.browse(cursor, user, act[1], context=context)
|
|
|
|
|
if move.to_location.id != \
|
|
|
|
|
packing.warehouse.input_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'incoming_move_input_dest', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'set':
|
|
|
|
|
moves = move_obj.browse(cursor, user, act[1], context=context)
|
|
|
|
|
for move in moves:
|
|
|
|
|
if move.to_location.id != \
|
|
|
|
|
packing.warehouse.input_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'incoming_move_input_dest', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
self.write(cursor, user, packing_id, {
|
|
|
|
|
'moves': value,
|
|
|
|
|
}, context=context)
|
|
|
|
|
|
|
|
|
|
def get_inventory_moves(self, cursor, user, ids, name, arg, context=None):
|
|
|
|
|
res = {}
|
|
|
|
|
for packing in self.browse(cursor, user, ids, context=context):
|
|
|
|
|
res[packing.id] = []
|
|
|
|
|
for move in packing.moves:
|
|
|
|
|
if move.from_location.id == packing.warehouse.input_location.id:
|
|
|
|
|
res[packing.id].append(move.id)
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
def set_inventory_moves(self, cursor, user, packing_id, name, value, arg,
|
|
|
|
|
context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
for act in value:
|
|
|
|
|
if act[0] == 'create':
|
|
|
|
|
if 'from_location' in act[1]:
|
|
|
|
|
if act[1]['from_location'] != \
|
|
|
|
|
packing.warehouse.input_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'inventory_move_input_source', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'write':
|
|
|
|
|
if 'from_location' in act[2]:
|
|
|
|
|
if act[2]['from_location'] != \
|
|
|
|
|
packing.warehouse.input_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'inventory_move_input_source', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'add':
|
|
|
|
|
move = move_obj.browse(cursor, user, act[1], context=context)
|
|
|
|
|
if move.from_location.id != \
|
|
|
|
|
packing.warehouse.input_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'inventory_move_input_source', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'set':
|
|
|
|
|
moves = move_obj.browse(cursor, user, act[1], context=context)
|
|
|
|
|
for move in moves:
|
|
|
|
|
if move.from_location.id != \
|
|
|
|
|
packing.warehouse.input_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'inventory_move_input_source', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
self.write(cursor, user, packing_id, {
|
|
|
|
|
'moves': value,
|
|
|
|
|
}, context=context)
|
|
|
|
|
|
2008-04-17 02:31:55 +02:00
|
|
|
def set_state_done(self, cursor, user, packing_id, context=None):
|
2008-04-08 14:27:53 +02:00
|
|
|
move_obj = self.pool.get('stock.move')
|
2008-04-17 02:31:55 +02:00
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
move_obj.set_state_done(
|
|
|
|
|
cursor, user, [m.id for m in packing.inventory_moves], context)
|
2008-05-13 13:10:49 +02:00
|
|
|
self.write(cursor, user, packing_id,{
|
|
|
|
|
'state': 'done',
|
|
|
|
|
'effective_date': datetime.datetime.now(),
|
|
|
|
|
}, context=context)
|
2008-04-08 14:27:53 +02:00
|
|
|
|
2008-04-17 02:31:55 +02:00
|
|
|
def set_state_cancel(self, cursor, user, packing_id, context=None):
|
2008-04-08 14:27:53 +02:00
|
|
|
move_obj = self.pool.get('stock.move')
|
2008-04-17 02:31:55 +02:00
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
move_obj.set_state_cancel(
|
|
|
|
|
cursor, user, [m.id for m in packing.incoming_moves] +\
|
|
|
|
|
[m.id for m in packing.inventory_moves], context)
|
|
|
|
|
self.write(cursor, user, packing_id, {'state':'cancel'},
|
|
|
|
|
context=context)
|
2008-04-08 14:27:53 +02:00
|
|
|
|
2008-04-17 02:31:55 +02:00
|
|
|
def set_state_received(self, cursor, user, packing_id, context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
2008-05-13 13:10:49 +02:00
|
|
|
move_obj.set_state_done(cursor, user,
|
|
|
|
|
[m.id for m in packing.incoming_moves], context=context)
|
|
|
|
|
self.write(cursor, user, packing_id, {
|
|
|
|
|
'state': 'received'
|
|
|
|
|
}, context=context)
|
2008-04-17 02:31:55 +02:00
|
|
|
|
|
|
|
|
def set_state_draft(self, cursor, user, packing_id, context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
2008-10-21 17:02:16 +02:00
|
|
|
move_obj.set_state_cancel(cursor, user,
|
|
|
|
|
[m.id for m in packing.incoming_moves], context=context)
|
2008-07-07 15:54:10 +02:00
|
|
|
move_obj.set_state_draft(cursor, user,
|
|
|
|
|
[m.id for m in packing.incoming_moves], context=context)
|
2008-07-25 12:49:38 +02:00
|
|
|
move_obj.delete(cursor, user,
|
2008-07-07 15:54:10 +02:00
|
|
|
[m.id for m in packing.inventory_moves], context=context)
|
|
|
|
|
self.write(cursor, user, packing_id, {
|
|
|
|
|
'state': 'draft',
|
|
|
|
|
}, context=context)
|
2008-04-17 02:31:55 +02:00
|
|
|
|
|
|
|
|
def create(self, cursor, user, values, context=None):
|
2008-05-07 19:01:29 +02:00
|
|
|
values = values.copy()
|
2008-04-17 02:31:55 +02:00
|
|
|
values['code'] = self.pool.get('ir.sequence').get(
|
|
|
|
|
cursor, user, 'stock.packing.in')
|
|
|
|
|
return super(PackingIn, self).create(
|
|
|
|
|
cursor, user, values, context=context)
|
|
|
|
|
|
2008-05-07 18:04:25 +02:00
|
|
|
def _get_inventory_moves(self, cursor, user, incoming_move, context=None):
|
|
|
|
|
res = {}
|
|
|
|
|
if incoming_move.quantity <= 0.0:
|
|
|
|
|
return None
|
|
|
|
|
res['product'] = incoming_move.product.id
|
|
|
|
|
res['uom'] = incoming_move.uom.id
|
|
|
|
|
res['quantity'] = incoming_move.quantity
|
|
|
|
|
res['from_location'] = incoming_move.to_location.id
|
|
|
|
|
res['to_location'] = incoming_move.packing_in.warehouse.\
|
|
|
|
|
storage_location.id
|
2008-07-07 15:54:10 +02:00
|
|
|
res['state'] = 'draft'
|
2008-05-13 13:10:49 +02:00
|
|
|
res['company'] = incoming_move.company.id
|
2008-05-07 18:04:25 +02:00
|
|
|
return res
|
2008-05-01 15:48:04 +02:00
|
|
|
|
2008-05-07 18:04:25 +02:00
|
|
|
def create_inventory_moves(self, cursor, user, packing_id, context=None):
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
for incoming_move in packing.incoming_moves:
|
|
|
|
|
vals = self._get_inventory_moves(cursor, user, incoming_move,
|
|
|
|
|
context=context)
|
|
|
|
|
if vals:
|
|
|
|
|
self.write(cursor, user, packing.id, {
|
|
|
|
|
'inventory_moves': [('create', vals)]
|
|
|
|
|
}, context=context)
|
2008-04-08 14:27:53 +02:00
|
|
|
|
2008-05-08 17:24:49 +02:00
|
|
|
def button_draft(self, cursor, user, ids, context=None):
|
|
|
|
|
workflow_service = LocalService('workflow')
|
|
|
|
|
for packing in self.browse(cursor, user, ids, context=context):
|
|
|
|
|
workflow_service.trg_create(user, self._name, packing.id, cursor)
|
|
|
|
|
return True
|
|
|
|
|
|
2008-04-08 14:27:53 +02:00
|
|
|
PackingIn()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PackingOut(OSV):
|
|
|
|
|
"Customer Packing"
|
|
|
|
|
_name = 'stock.packing.out'
|
|
|
|
|
_description = __doc__
|
2008-04-17 02:31:55 +02:00
|
|
|
_rec_name = 'code'
|
2008-04-08 14:27:53 +02:00
|
|
|
|
2008-06-11 20:18:37 +02:00
|
|
|
effective_date =fields.DateTime('Effective Date', readonly=True)
|
2008-08-26 16:12:16 +02:00
|
|
|
planned_date = fields.DateTime('Planned Date',
|
2008-05-21 18:14:52 +02:00
|
|
|
states={
|
|
|
|
|
'readonly': "state != 'draft'",
|
|
|
|
|
})
|
|
|
|
|
customer = fields.Many2One('relationship.party', 'Customer', required=True,
|
|
|
|
|
states={
|
|
|
|
|
'readonly': "state != 'draft'",
|
|
|
|
|
}, on_change=['customer'])
|
|
|
|
|
delivery_address = fields.Many2One('relationship.address',
|
|
|
|
|
'Delivery Address', required=True,
|
|
|
|
|
states={
|
|
|
|
|
'readonly': "state != 'draft'",
|
|
|
|
|
}, domain="[('party', '=', customer)]")
|
|
|
|
|
reference = fields.Char("Reference", size=None, select=1,
|
|
|
|
|
states={
|
|
|
|
|
'readonly': "state != 'draft'",
|
|
|
|
|
})
|
2008-05-07 18:04:25 +02:00
|
|
|
warehouse = fields.Many2One('stock.location', "Warehouse", required=True,
|
|
|
|
|
states={
|
|
|
|
|
'readonly': "state != 'draft'",
|
|
|
|
|
}, domain="[('type', '=', 'warehouse')]")
|
|
|
|
|
customer_location = fields.Many2One('stock.location', "Customer Location",
|
|
|
|
|
required=True, states={
|
|
|
|
|
'readonly': "state != 'draft'",
|
|
|
|
|
}, domain="[('type', '=', 'customer')]")
|
|
|
|
|
outgoing_moves = fields.Function('get_outgoing_moves', type='one2many',
|
|
|
|
|
relation='stock.move', string='Outgoing Moves',
|
|
|
|
|
fnct_inv='set_outgoing_moves',
|
|
|
|
|
states={
|
2008-05-20 19:21:36 +02:00
|
|
|
'readonly':"state != 'packed'",
|
2008-07-07 15:54:10 +02:00
|
|
|
}, context="{'warehouse': warehouse, 'type':'outgoing',}")
|
2008-05-07 18:04:25 +02:00
|
|
|
inventory_moves = fields.Function('get_inventory_moves', type='one2many',
|
|
|
|
|
relation='stock.move', string='Inventory Moves',
|
|
|
|
|
fnct_inv='set_inventory_moves',
|
|
|
|
|
states={
|
2008-05-20 19:21:36 +02:00
|
|
|
'readonly':"state in ('packed', 'done')",
|
2008-07-07 15:54:10 +02:00
|
|
|
}, context="{'warehouse': warehouse, 'type':'inventory_out',}")
|
2008-05-16 01:18:55 +02:00
|
|
|
moves = fields.One2Many('stock.move', 'packing_out', 'Moves',
|
2008-05-07 18:04:25 +02:00
|
|
|
readonly=True)
|
|
|
|
|
code = fields.Char("Code", size=None, select=1, readonly=True)
|
|
|
|
|
state = fields.Selection([
|
|
|
|
|
('draft', 'Draft'),
|
|
|
|
|
('done', 'Done'),
|
|
|
|
|
('cancel', 'Cancel'),
|
|
|
|
|
('assigned', 'Assigned'),
|
2008-05-20 19:21:36 +02:00
|
|
|
('packed', 'Packed'),
|
2008-05-07 18:04:25 +02:00
|
|
|
('waiting', 'Waiting'),
|
|
|
|
|
], 'State', readonly=True)
|
2008-04-08 14:27:53 +02:00
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(PackingOut, self).__init__()
|
|
|
|
|
self._rpc_allowed += [
|
2008-05-13 17:42:23 +02:00
|
|
|
'button_draft',
|
|
|
|
|
]
|
2008-04-22 17:49:50 +02:00
|
|
|
self._order[0] = ('id', 'DESC')
|
2008-04-08 14:27:53 +02:00
|
|
|
|
|
|
|
|
def default_state(self, cursor, user, context=None):
|
|
|
|
|
return 'draft'
|
|
|
|
|
|
2008-05-20 19:20:25 +02:00
|
|
|
def on_change_customer(self, cursor, user, ids, values, context=None):
|
|
|
|
|
if not values.get('customer'):
|
2008-05-16 01:46:44 +02:00
|
|
|
return {}
|
2008-05-21 18:14:52 +02:00
|
|
|
party_obj = self.pool.get("relationship.party")
|
|
|
|
|
address_id = party_obj.address_get(cursor, user, values['customer'],
|
|
|
|
|
type='delivery', context=context)
|
|
|
|
|
party = party_obj.browse(cursor, user, values['customer'], context=context)
|
|
|
|
|
return {
|
|
|
|
|
'delivery_address': address_id,
|
|
|
|
|
'customer_location': party.customer_location.id,
|
|
|
|
|
}
|
2008-05-16 01:46:44 +02:00
|
|
|
|
2008-05-07 18:04:25 +02:00
|
|
|
def get_outgoing_moves(self, cursor, user, ids, name, arg, context=None):
|
|
|
|
|
res = {}
|
|
|
|
|
for packing in self.browse(cursor, user, ids, context=context):
|
|
|
|
|
res[packing.id] = []
|
|
|
|
|
for move in packing.moves:
|
|
|
|
|
if move.from_location.id == \
|
|
|
|
|
packing.warehouse.output_location.id:
|
|
|
|
|
res[packing.id].append(move.id)
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
def set_outgoing_moves(self, cursor, user, packing_id, name, value, arg,
|
|
|
|
|
context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
for act in value:
|
|
|
|
|
if act[0] == 'create':
|
|
|
|
|
if 'from_location' in act[1]:
|
|
|
|
|
if act[1]['from_location'] != \
|
|
|
|
|
packing.warehouse.output_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'outgoing_move_output_source', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'write':
|
|
|
|
|
if 'from_location' in act[2]:
|
|
|
|
|
if act[2]['from_location'] != \
|
|
|
|
|
packing.warehouse.output_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'outgoing_move_output_source', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'add':
|
|
|
|
|
move = move_obj.browse(cursor, user, act[1], context=context)
|
|
|
|
|
if move.from_location.id != \
|
|
|
|
|
packing.warehouse.output_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'outgoing_move_output_source', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'set':
|
|
|
|
|
moves = move_obj.browse(cursor, user, act[1], context=context)
|
|
|
|
|
for move in moves:
|
|
|
|
|
if move.from_location.id != \
|
|
|
|
|
packing.warehouse.output_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'outgoing_move_output_source', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
self.write(cursor, user, packing_id, {
|
|
|
|
|
'moves': value,
|
|
|
|
|
}, context=context)
|
|
|
|
|
|
|
|
|
|
def get_inventory_moves(self, cursor, user, ids, name, arg, context=None):
|
|
|
|
|
res = {}
|
|
|
|
|
for packing in self.browse(cursor, user, ids, context=context):
|
|
|
|
|
res[packing.id] = []
|
|
|
|
|
for move in packing.moves:
|
|
|
|
|
if move.to_location.id == \
|
|
|
|
|
packing.warehouse.output_location.id:
|
|
|
|
|
res[packing.id].append(move.id)
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
def set_inventory_moves(self, cursor, user, packing_id, name, value, arg,
|
|
|
|
|
context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
for act in value:
|
|
|
|
|
if act[0] == 'create':
|
|
|
|
|
if 'to_location' in act[1]:
|
|
|
|
|
if act[1]['to_location'] != \
|
|
|
|
|
packing.warehouse.output_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'inventory_move_output_dest', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'write':
|
|
|
|
|
if 'to_location' in act[2]:
|
|
|
|
|
if act[2]['to_location'] != \
|
|
|
|
|
packing.warehouse.output_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'inventory_move_output_dest', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'add':
|
|
|
|
|
move = move_obj.browse(cursor, user, act[1], context=context)
|
|
|
|
|
if move.to_location.id != \
|
|
|
|
|
packing.warehouse.output_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'inventory_move_output_dest', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
elif act[0] == 'set':
|
|
|
|
|
moves = move_obj.browse(cursor, user, act[1], context=context)
|
|
|
|
|
for move in moves:
|
|
|
|
|
if move.to_location.id != \
|
|
|
|
|
packing.warehouse.output_location.id:
|
2008-07-17 19:37:38 +02:00
|
|
|
self.raise_user_error(cursor,
|
|
|
|
|
'inventory_move_output_dest', context=context)
|
2008-05-07 18:04:25 +02:00
|
|
|
self.write(cursor, user, packing_id, {
|
|
|
|
|
'moves': value,
|
|
|
|
|
}, context=context)
|
|
|
|
|
|
2008-04-28 22:40:38 +02:00
|
|
|
def set_state_assigned(self, cursor, user, packing_id, context=None):
|
|
|
|
|
self.write(cursor, user, packing_id, {'state':'assigned'},
|
|
|
|
|
context=context)
|
|
|
|
|
|
2008-08-26 15:51:21 +02:00
|
|
|
def set_state_draft(self, cursor, user, packing_id, context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
self.write(
|
|
|
|
|
cursor, user, packing_id, {'state':'draft'}, context=context)
|
2008-10-21 17:02:16 +02:00
|
|
|
move_obj.set_state_cancel(
|
|
|
|
|
cursor, user,
|
|
|
|
|
[m.id for m in packing.inventory_moves + packing.outgoing_moves],
|
|
|
|
|
context=context)
|
2008-08-26 15:51:21 +02:00
|
|
|
move_obj.set_state_draft(
|
|
|
|
|
cursor, user,
|
|
|
|
|
[m.id for m in packing.inventory_moves + packing.outgoing_moves],
|
|
|
|
|
context=context)
|
|
|
|
|
|
2008-04-17 02:31:55 +02:00
|
|
|
def set_state_done(self, cursor, user, packing_id, context=None):
|
2008-04-08 14:27:53 +02:00
|
|
|
move_obj = self.pool.get('stock.move')
|
2008-04-17 02:31:55 +02:00
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
2008-07-07 15:54:10 +02:00
|
|
|
move_obj.set_state_done(cursor, user,
|
|
|
|
|
[m.id for m in packing.outgoing_moves if m.state == 'draft'],
|
2008-04-28 22:40:38 +02:00
|
|
|
context=context)
|
2008-07-07 15:54:10 +02:00
|
|
|
self.write(cursor, user, packing_id, {
|
|
|
|
|
'state':'done',
|
|
|
|
|
'effective_date': datetime.datetime.now(),
|
|
|
|
|
}, context=context)
|
2008-04-08 14:27:53 +02:00
|
|
|
|
2008-05-20 19:21:36 +02:00
|
|
|
def set_state_packed(self, cursor, user, packing_id, context=None):
|
2008-04-08 14:27:53 +02:00
|
|
|
move_obj = self.pool.get('stock.move')
|
2008-08-26 14:47:15 +02:00
|
|
|
uom_obj = self.pool.get('product.uom')
|
2008-04-17 02:31:55 +02:00
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
move_obj.set_state_done(
|
|
|
|
|
cursor, user, [m.id for m in packing.inventory_moves],
|
|
|
|
|
context=context)
|
2008-05-20 19:21:36 +02:00
|
|
|
self.write(cursor, user, packing_id, {'state':'packed'},
|
2008-04-17 02:31:55 +02:00
|
|
|
context=context)
|
2008-08-26 14:47:15 +02:00
|
|
|
# Sum all outgoing quantities
|
|
|
|
|
outgoing_qty = {}
|
|
|
|
|
for move in packing.outgoing_moves:
|
|
|
|
|
if move.state == 'cancel': continue
|
|
|
|
|
quantity = uom_obj.compute_qty(
|
|
|
|
|
cursor, user, move.uom, move.quantity, move.product.default_uom,
|
|
|
|
|
context=context)
|
|
|
|
|
outgoing_qty.setdefault(move.product.id, 0.0)
|
|
|
|
|
outgoing_qty[move.product.id] += quantity
|
|
|
|
|
|
2008-04-28 22:40:38 +02:00
|
|
|
for move in packing.inventory_moves:
|
2008-08-26 19:18:56 +02:00
|
|
|
if move.state == 'cancel': continue
|
2008-08-26 14:47:15 +02:00
|
|
|
qty_default_uom = uom_obj.compute_qty(
|
|
|
|
|
cursor, user, move.uom, move.quantity, move.product.default_uom,
|
|
|
|
|
context=context)
|
|
|
|
|
# Check if the outgoing move doesn't exist already
|
|
|
|
|
if outgoing_qty.get(move.product.id):
|
|
|
|
|
# If it exist, decrease the sum
|
|
|
|
|
if qty_default_uom <= outgoing_qty[move.product.id]:
|
|
|
|
|
outgoing_qty[move.product.id] -= qty_default_uom
|
|
|
|
|
continue
|
|
|
|
|
# Else create the complement
|
|
|
|
|
else:
|
|
|
|
|
out_quantity = qty_default_uom - outgoing_qty[move.product.id]
|
|
|
|
|
out_quantity = uom_obj.compute_qty(
|
|
|
|
|
cursor, user, move.product.default_uom, out_quantity,
|
|
|
|
|
move.uom, context=context)
|
2008-08-26 17:23:39 +02:00
|
|
|
outgoing_qty[move.product.id] = 0.0
|
2008-08-26 14:47:15 +02:00
|
|
|
else:
|
|
|
|
|
out_quantity = move.quantity
|
|
|
|
|
|
2008-10-06 12:15:15 +02:00
|
|
|
unit_price = uom_obj.compute_price(
|
|
|
|
|
cursor, user, move.product.default_uom, move.product.list_price,
|
|
|
|
|
move.uom, context=context)
|
2008-04-28 22:40:38 +02:00
|
|
|
move_obj.create(cursor, user, {
|
|
|
|
|
'from_location': move.to_location.id,
|
|
|
|
|
'to_location': packing.customer_location.id,
|
|
|
|
|
'product': move.product.id,
|
|
|
|
|
'uom': move.uom.id,
|
2008-08-26 14:47:15 +02:00
|
|
|
'quantity': out_quantity,
|
2008-05-16 01:29:39 +02:00
|
|
|
'packing_out': packing.id,
|
2008-07-07 15:54:10 +02:00
|
|
|
'state': 'draft',
|
2008-05-16 01:30:46 +02:00
|
|
|
'company': move.company.id,
|
2008-10-06 12:15:15 +02:00
|
|
|
'currency': move.company.currency.id,
|
|
|
|
|
'unit_price': unit_price,
|
2008-04-28 22:40:38 +02:00
|
|
|
}, context=context)
|
2008-04-08 14:27:53 +02:00
|
|
|
|
2008-08-26 17:23:39 +02:00
|
|
|
#Re-read the packing and remove exceeding quantities
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
for move in packing.outgoing_moves:
|
2008-08-26 19:18:56 +02:00
|
|
|
if move.state == 'cancel': continue
|
2008-08-26 17:23:39 +02:00
|
|
|
if outgoing_qty.get(move.product.id, 0.0) > 0.0:
|
|
|
|
|
exc_qty = uom_obj.compute_qty(
|
|
|
|
|
cursor, user, move.product.default_uom,
|
|
|
|
|
outgoing_qty[move.product.id], move.uom, context=context)
|
|
|
|
|
move_obj.write(cursor, user, move.id,{
|
|
|
|
|
'quantity': max(0.0, move.quantity-exc_qty),
|
|
|
|
|
}, context=context)
|
|
|
|
|
removed_qty = uom_obj.compute_qty(
|
|
|
|
|
cursor, user, move.uom, min(exc_qty, move.quantity),
|
|
|
|
|
move.product.default_uom, context=context)
|
|
|
|
|
outgoing_qty[move.product.id] -= removed_qty
|
|
|
|
|
|
|
|
|
|
|
2008-04-17 02:31:55 +02:00
|
|
|
def set_state_cancel(self, cursor, user, packing_id, context=None):
|
2008-04-08 14:27:53 +02:00
|
|
|
move_obj = self.pool.get('stock.move')
|
2008-04-17 02:31:55 +02:00
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
move_obj.set_state_cancel(
|
|
|
|
|
cursor, user,[m.id for m in packing.outgoing_moves] +\
|
|
|
|
|
[m.id for m in packing.inventory_moves],
|
|
|
|
|
context=context)
|
|
|
|
|
self.write(cursor, user, packing_id, {'state':'cancel'},
|
|
|
|
|
context=context)
|
2008-04-08 14:27:53 +02:00
|
|
|
|
2008-04-17 02:31:55 +02:00
|
|
|
def set_state_waiting(self, cursor, user, packing_id, context=None):
|
2008-10-06 12:18:36 +02:00
|
|
|
"""
|
|
|
|
|
Complete inventory moves to match the products and quantities
|
|
|
|
|
that are in the outgoing moves.
|
|
|
|
|
"""
|
2008-04-17 02:31:55 +02:00
|
|
|
move_obj = self.pool.get('stock.move')
|
2008-08-26 16:51:33 +02:00
|
|
|
uom_obj = self.pool.get('product.uom')
|
2008-04-17 02:31:55 +02:00
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
2008-10-21 17:02:16 +02:00
|
|
|
if packing.state == 'assigned':
|
|
|
|
|
move_obj.set_state_cancel(
|
|
|
|
|
cursor, user,
|
|
|
|
|
[m.id for m in packing.inventory_moves + packing.outgoing_moves],
|
|
|
|
|
context=context)
|
|
|
|
|
move_obj.set_state_draft(
|
|
|
|
|
cursor, user,
|
|
|
|
|
[m.id for m in packing.inventory_moves + packing.outgoing_moves],
|
|
|
|
|
context=context)
|
2008-08-26 16:51:33 +02:00
|
|
|
self.write(
|
|
|
|
|
cursor, user, packing_id, {'state':'waiting'}, context=context)
|
|
|
|
|
|
|
|
|
|
# Sum all inventory quantities
|
|
|
|
|
inventory_qty = {}
|
|
|
|
|
for move in packing.inventory_moves:
|
|
|
|
|
if move.state == 'cancel': continue
|
|
|
|
|
quantity = uom_obj.compute_qty(
|
|
|
|
|
cursor, user, move.uom, move.quantity, move.product.default_uom,
|
2008-07-07 15:54:10 +02:00
|
|
|
context=context)
|
2008-08-26 16:51:33 +02:00
|
|
|
inventory_qty.setdefault(move.product.id, 0.0)
|
|
|
|
|
inventory_qty[move.product.id] += quantity
|
|
|
|
|
|
|
|
|
|
for move in packing.outgoing_moves:
|
|
|
|
|
if move.state in ('cancel', 'done'): continue
|
|
|
|
|
qty_default_uom = uom_obj.compute_qty(
|
|
|
|
|
cursor, user, move.uom, move.quantity, move.product.default_uom,
|
|
|
|
|
context=context)
|
|
|
|
|
# Check if the inventory move doesn't exist already
|
|
|
|
|
if inventory_qty.get(move.product.id):
|
|
|
|
|
# If it exist, decrease the sum
|
|
|
|
|
if qty_default_uom <= inventory_qty[move.product.id]:
|
|
|
|
|
inventory_qty[move.product.id] -= qty_default_uom
|
|
|
|
|
continue
|
|
|
|
|
# Else create the complement
|
|
|
|
|
else:
|
|
|
|
|
inv_quantity = qty_default_uom - inventory_qty[move.product.id]
|
|
|
|
|
inv_quantity = uom_obj.compute_qty(
|
|
|
|
|
cursor, user, move.product.default_uom, inv_quantity,
|
|
|
|
|
move.uom, context=context)
|
2008-08-26 17:23:39 +02:00
|
|
|
inventory_qty[move.product.id] = 0.0
|
2008-08-26 16:51:33 +02:00
|
|
|
else:
|
|
|
|
|
inv_quantity = move.quantity
|
|
|
|
|
|
|
|
|
|
move_obj.create(cursor, user, {
|
|
|
|
|
'from_location': move.packing_out.warehouse.storage_location.id,
|
|
|
|
|
'to_location': move.from_location.id,
|
|
|
|
|
'product': move.product.id,
|
|
|
|
|
'uom': move.uom.id,
|
|
|
|
|
'quantity': inv_quantity,
|
|
|
|
|
'packing_out': packing.id,
|
|
|
|
|
'state': 'draft',
|
|
|
|
|
'company': move.company.id,
|
|
|
|
|
}, context=context)
|
2008-04-17 02:31:55 +02:00
|
|
|
|
|
|
|
|
def create(self, cursor, user, values, context=None):
|
|
|
|
|
values['code'] = self.pool.get('ir.sequence').get(
|
|
|
|
|
cursor, user, 'stock.packing.out')
|
|
|
|
|
return super(PackingOut, self).create(cursor, user, values,
|
|
|
|
|
context=context)
|
|
|
|
|
|
2008-04-28 22:40:38 +02:00
|
|
|
def _location_amount(self, cursor, user, target_uom,
|
2008-07-09 18:08:37 +02:00
|
|
|
qty_uom, uom_index, context=None):
|
2008-04-22 01:03:40 +02:00
|
|
|
"""
|
2008-04-28 22:40:38 +02:00
|
|
|
Take a raw list of quantities and uom and convert it to
|
|
|
|
|
the target uom.
|
2008-04-22 01:03:40 +02:00
|
|
|
"""
|
|
|
|
|
uom_obj = self.pool.get('product.uom')
|
2008-04-28 22:40:38 +02:00
|
|
|
res = 0
|
2008-07-09 18:08:37 +02:00
|
|
|
for uom, qty in qty_uom:
|
2008-04-28 22:40:38 +02:00
|
|
|
res += uom_obj.compute_qty(
|
2008-07-09 15:53:50 +02:00
|
|
|
cursor, user, uom_index[uom], qty, uom_index[target_uom],
|
|
|
|
|
context=context)
|
2008-04-22 01:03:40 +02:00
|
|
|
return res
|
2008-04-18 01:54:48 +02:00
|
|
|
|
2008-07-07 15:54:10 +02:00
|
|
|
def assign_try(self, cursor, user, packing_id, context=None):
|
2008-04-28 22:40:38 +02:00
|
|
|
product_obj = self.pool.get('product.product')
|
2008-07-07 15:54:10 +02:00
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
2008-10-06 12:19:50 +02:00
|
|
|
return product_obj.assign_try(
|
|
|
|
|
cursor, user, packing.inventory_moves, context=context)
|
2008-04-17 02:31:55 +02:00
|
|
|
|
2008-07-07 15:54:10 +02:00
|
|
|
def assign_force(self, cursor, user, packing_id, context=None):
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
2008-04-22 01:03:40 +02:00
|
|
|
move_obj = self.pool.get('stock.move')
|
2008-05-07 02:20:02 +02:00
|
|
|
move_obj.write(
|
|
|
|
|
cursor, user, [m.id for m in packing.inventory_moves],
|
|
|
|
|
{'state':'assigned'})
|
2008-04-17 02:31:55 +02:00
|
|
|
return True
|
2008-04-08 14:27:53 +02:00
|
|
|
|
2008-05-13 17:42:23 +02:00
|
|
|
def button_draft(self, cursor, user, ids, context=None):
|
|
|
|
|
workflow_service = LocalService('workflow')
|
|
|
|
|
for packing in self.browse(cursor, user, ids, context=context):
|
|
|
|
|
workflow_service.trg_create(user, self._name, packing.id, cursor)
|
|
|
|
|
|
2008-04-08 14:27:53 +02:00
|
|
|
PackingOut()
|
2008-05-08 12:49:46 +02:00
|
|
|
|
2008-10-06 12:20:19 +02:00
|
|
|
class PackingInternal(OSV):
|
|
|
|
|
"Internal Packing"
|
|
|
|
|
_name = 'stock.packing.internal'
|
|
|
|
|
_description = __doc__
|
|
|
|
|
_rec_name = 'code'
|
|
|
|
|
|
|
|
|
|
effective_date =fields.DateTime('Effective Date', readonly=True)
|
|
|
|
|
planned_date = fields.DateTime(
|
|
|
|
|
'Planned Date', states={'readonly': "state != 'draft'",})
|
|
|
|
|
code = fields.Char("Code", size=None, select=1, readonly=True)
|
|
|
|
|
reference = fields.Char(
|
|
|
|
|
"Reference", size=None, select=1,
|
|
|
|
|
states={'readonly': "state != 'draft'",})
|
|
|
|
|
from_location = fields.Many2One(
|
|
|
|
|
'stock.location', "From Location", required=True,
|
|
|
|
|
states={ 'readonly': "state != 'draft'", },
|
|
|
|
|
domain="[('type', '=', 'storage')]", )
|
|
|
|
|
to_location = fields.Many2One('stock.location', "To Location",
|
|
|
|
|
required=True, states={
|
|
|
|
|
'readonly': "state != 'draft'",
|
|
|
|
|
}, domain="[('type', '=', 'storage')]")
|
|
|
|
|
moves = fields.One2Many(
|
|
|
|
|
'stock.move', 'packing_internal', 'Moves',
|
|
|
|
|
states={'readonly': "state != 'draft'"},
|
|
|
|
|
context="{'from_location': from_location,"
|
|
|
|
|
"'to_location': to_location,"
|
|
|
|
|
"'planned_date': planned_date}",
|
|
|
|
|
)
|
|
|
|
|
state = fields.Selection([
|
|
|
|
|
('draft', 'Draft'),
|
|
|
|
|
('cancel', 'Cancel'),
|
|
|
|
|
('assigned', 'Assigned'),
|
|
|
|
|
('waiting', 'Waiting'),
|
|
|
|
|
('done', 'Done'),
|
|
|
|
|
], 'State', readonly=True)
|
|
|
|
|
|
|
|
|
|
def default_state(self, cursor, user, context=None):
|
|
|
|
|
return 'draft'
|
|
|
|
|
|
|
|
|
|
def button_draft(self, cursor, user, ids, context=None):
|
|
|
|
|
workflow_service = LocalService('workflow')
|
|
|
|
|
for packing in self.browse(cursor, user, ids, context=context):
|
|
|
|
|
workflow_service.trg_create(user, self._name, packing.id, cursor)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(PackingInternal, self).__init__()
|
|
|
|
|
self._rpc_allowed += [
|
|
|
|
|
'button_draft',
|
|
|
|
|
]
|
|
|
|
|
self._order[0] = ('id', 'DESC')
|
|
|
|
|
|
|
|
|
|
def set_state_draft(self, cursor, user, packing_id, context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
self.write(
|
|
|
|
|
cursor, user, packing_id, {'state':'draft'}, context=context)
|
2008-10-21 17:02:16 +02:00
|
|
|
move_obj.set_state_cancel(
|
|
|
|
|
cursor, user, [m.id for m in packing.moves], context=context)
|
2008-10-06 12:20:19 +02:00
|
|
|
move_obj.set_state_draft(
|
|
|
|
|
cursor, user, [m.id for m in packing.moves], context=context)
|
|
|
|
|
|
|
|
|
|
def set_state_waiting(self, cursor, user, packing_id, context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
2008-10-21 17:02:16 +02:00
|
|
|
move_obj.set_state_cancel(
|
|
|
|
|
cursor, user, [m.id for m in packing.moves], context=context)
|
|
|
|
|
move_obj.set_state_draft(
|
|
|
|
|
cursor, user, [m.id for m in packing.moves], context=context)
|
2008-10-06 12:20:19 +02:00
|
|
|
move_obj.write(
|
|
|
|
|
cursor, user, [m.id for m in packing.moves],
|
|
|
|
|
{'planned_date': packing.planned_date}, context=context)
|
|
|
|
|
self.write(
|
|
|
|
|
cursor, user, packing_id, {'state':'waiting'}, context=context)
|
|
|
|
|
|
|
|
|
|
def set_state_assigned(self, cursor, user, packing_id, context=None):
|
|
|
|
|
self.write(
|
|
|
|
|
cursor, user, packing_id, {'state':'assigned'}, context=context)
|
|
|
|
|
|
|
|
|
|
def set_state_done(self, cursor, user, packing_id, context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
move_obj.set_state_done(
|
|
|
|
|
cursor, user, [m.id for m in packing.moves], context=context)
|
|
|
|
|
self.write( cursor, user, packing_id,
|
|
|
|
|
{'state':'done',
|
|
|
|
|
'effective_date': datetime.datetime.now()},
|
|
|
|
|
context=context)
|
|
|
|
|
|
|
|
|
|
def set_state_cancel(self, cursor, user, packing_id, context=None):
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
move_obj.set_state_cancel(
|
|
|
|
|
cursor, user, [m.id for m in packing.moves], context=context)
|
|
|
|
|
self.write(
|
|
|
|
|
cursor, user, packing_id, {'state':'cancel'}, context=context)
|
|
|
|
|
|
|
|
|
|
def assign_try(self, cursor, user, packing_id, context=None):
|
|
|
|
|
product_obj = self.pool.get('product.product')
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
return product_obj.assign_try(
|
|
|
|
|
cursor, user, packing.moves, context=context)
|
|
|
|
|
|
|
|
|
|
def assign_force(self, cursor, user, packing_id, context=None):
|
|
|
|
|
packing = self.browse(cursor, user, packing_id, context=context)
|
|
|
|
|
move_obj = self.pool.get('stock.move')
|
|
|
|
|
move_obj.write(
|
|
|
|
|
cursor, user, [m.id for m in packing.moves], {'state':'assigned'})
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
PackingInternal()
|
2008-05-08 12:49:46 +02:00
|
|
|
|
2008-05-20 19:20:25 +02:00
|
|
|
class Address(OSV):
|
2008-05-21 18:14:52 +02:00
|
|
|
_name = 'relationship.address'
|
2008-05-20 19:20:25 +02:00
|
|
|
delivery = fields.Boolean('Delivery')
|
|
|
|
|
|
|
|
|
|
Address()
|
|
|
|
|
|
|
|
|
|
|
2008-05-16 01:53:15 +02:00
|
|
|
class PackingOutReport(CompanyReport):
|
|
|
|
|
_name = 'stock.packing.out'
|
|
|
|
|
|
2008-05-20 14:00:54 +02:00
|
|
|
def parse(self, cursor, user, report, objects, datas, context):
|
|
|
|
|
if context is None:
|
|
|
|
|
context = {}
|
|
|
|
|
context = context.copy()
|
2008-07-17 21:23:48 +02:00
|
|
|
context['product_name'] = lambda product_id, language: \
|
|
|
|
|
self.product_name(cursor, user, product_id, language,
|
|
|
|
|
context)
|
2008-05-20 14:00:54 +02:00
|
|
|
return super(PackingOutReport, self).parse(cursor, user, report,
|
|
|
|
|
objects, datas, context)
|
|
|
|
|
|
2008-07-17 21:23:48 +02:00
|
|
|
def product_name(self, cursor, user, product_id, language, context):
|
2008-05-20 14:00:54 +02:00
|
|
|
product_obj = self.pool.get('product.product')
|
|
|
|
|
ctx = context.copy()
|
2008-07-17 21:23:48 +02:00
|
|
|
ctx['language'] = language
|
|
|
|
|
return product_obj.name_get(cursor, user, [product_id],
|
|
|
|
|
context=ctx)[0][1]
|
2008-05-20 14:00:54 +02:00
|
|
|
|
2008-05-16 01:53:15 +02:00
|
|
|
PackingOutReport()
|