From 06e7359da75536e35032fbf2a9ce2de131e3f0af Mon Sep 17 00:00:00 2001
From: "nel@tinyerp.com" <>
Date: Tue, 15 Jun 2010 21:19:08 +0200
Subject: [PATCH] [FIX] sale: problem of company id on move and picking when
validating SO add button set last track name
bzr revid: nel@tinyerp.com-20100615191908-nmcdaihdz04zof1r
---
addons/sale/__openerp__.py | 2 +-
addons/stock/security/ir.model.access.csv | 2 ++
addons/stock/stock.py | 20 +++++++++++++++++---
addons/stock/stock_view.xml | 18 ++++++++++++++++++
addons/stock/wizard/stock_splitinto.py | 5 +++++
addons/stock/wizard/stock_splitinto_view.xml | 3 ++-
6 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/addons/sale/__openerp__.py b/addons/sale/__openerp__.py
index 2f265b3d6f7..bacfc3b7abe 100644
--- a/addons/sale/__openerp__.py
+++ b/addons/sale/__openerp__.py
@@ -60,7 +60,7 @@
'stock_view.xml',
# 'process/sale_process.xml',
],
- 'demo_xml': ['sale_demo.xml'],
+ # 'demo_xml': ['sale_demo.xml'],
'test': [
'test/shipping_manual_sale_order.yml',
'test/prepaid_sale_order.yml',
diff --git a/addons/stock/security/ir.model.access.csv b/addons/stock/security/ir.model.access.csv
index 803431d8bd0..9b8c7a100b3 100644
--- a/addons/stock/security/ir.model.access.csv
+++ b/addons/stock/security/ir.model.access.csv
@@ -42,3 +42,5 @@
"access_stock_inventory_merge","stock.inventory.merge","model_stock_inventory_merge","stock.group_stock_user",1,0,0,0
"access_stock_change_standard_price","stock.change.standard.price","model_stock_change_standard_price","stock.group_stock_user",1,0,0,0
"access_action_traceability","action.traceability","model_action_traceability","stock.group_stock_user",1,0,0,0
+"access_stock_split_into","stock.split.into","model_stock_split_into","stock.group_stock_user",1,0,0,0
+"access_stock_split_into_manager","stock.split.into","model_stock_split_into","stock.group_stock_manager",1,1,1,1
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index bf308f191b5..0d8bda2f2f3 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -612,7 +612,7 @@ class stock_picking(osv.osv):
'type': lambda *a: 'in',
'invoice_state': lambda *a: 'none',
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
- 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock_picking', context=c)
+ 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.picking', context=c)
}
def copy(self, cr, uid, id, default=None, context={}):
@@ -1302,6 +1302,7 @@ stock_production_lot_revision()
# location_dest_id is only used for predicting futur stocks
#
class stock_move(osv.osv):
+
def _getSSCC(self, cr, uid, context={}):
cr.execute('select id from stock_tracking where create_uid=%s order by id desc limit 1', (uid,))
res = cr.fetchone()
@@ -1572,6 +1573,7 @@ class stock_move(osv.osv):
def create_chained_picking(self, cr, uid, moves, context):
new_moves = []
+ res_obj = self.pool.get('res.company')
for picking, todo in self._chain_compute(cr, uid, moves, context).items():
ptype = todo[0][1][5] and todo[0][1][5] or self.pool.get('stock.location').picking_type_get(cr, uid, todo[0][0].location_dest_id, todo[0][1][0])
pick_name = ''
@@ -1585,8 +1587,9 @@ class stock_move(osv.osv):
'move_type': picking.move_type,
'auto_picking': todo[0][1][1] == 'auto',
'stock_journal_id': todo[0][1][3],
- 'company_id': todo[0][1][4],
+ 'company_id': todo[0][1][4] or res_obj._company_default_get(cr, uid, 'stock.company', context),
'address_id': picking.address_id.id,
+
'invoice_state': 'none'
})
for move, (loc, auto, delay, journal, company_id, ptype) in todo:
@@ -1596,7 +1599,7 @@ class stock_move(osv.osv):
'date_moved': time.strftime('%Y-%m-%d'),
'picking_id': pickid,
'state': 'waiting',
- 'company_id': company_id,
+ 'company_id': company_id or res_obj._company_default_get(cr, uid, 'stock.company', context) ,
'move_history_ids': [],
'date_planned': (datetime.strptime(move.date_planned, '%Y-%m-%d %H:%M:%S') + relativedelta(days=delay or 0)).strftime('%Y-%m-%d'),
'move_history_ids2': []}
@@ -1682,6 +1685,17 @@ class stock_move(osv.osv):
wf_service.trg_write(uid, 'stock.picking', pick_id, cr)
return count
+ def setlast_tracking(self, cr, uid, ids, context=None):
+ new_move = []
+ update_val = {}
+ last_prod = [line.prodlot_id for line in self.browse(cr, uid, ids)[0].picking_id.move_lines if line.prodlot_id]
+ last_prod.sort(key=lambda p: p.date, reverse=True)
+ last_prod_id = last_prod and last_prod[0].id
+ update_val['prodlot_id'] = last_prod_id
+ self.write(cr, uid, ids, update_val)
+ return True
+
+
#
# Cancel move => cancel others move and pickings
#
diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml
index f23306c64aa..7cef0343edc 100644
--- a/addons/stock/stock_view.xml
+++ b/addons/stock/stock_view.xml
@@ -636,6 +636,9 @@
+
@@ -788,6 +791,9 @@
+
@@ -985,6 +991,9 @@
+
@@ -1171,6 +1180,9 @@
+
+
@@ -1511,6 +1526,9 @@
+
diff --git a/addons/stock/wizard/stock_splitinto.py b/addons/stock/wizard/stock_splitinto.py
index a3b372d7eb8..dcc97d6379d 100644
--- a/addons/stock/wizard/stock_splitinto.py
+++ b/addons/stock/wizard/stock_splitinto.py
@@ -56,12 +56,16 @@ class stock_split_into(osv.osv_memory):
update_val = {}
value_to_split = self.browse(cr, uid, data[0], context)
quantity = value_to_split.quantity or 0.0
+ ir_sequence_obj = self.pool.get('ir.sequence')
+ prodlot_obj = self.pool.get('stock.production.lot')
for move in move_obj.browse(cr, uid, rec_id):
move_qty = move.product_qty
uos_qty_rest = move.product_uos_qty
quantity_rest = move_qty - quantity
if quantity_rest == 0:
continue
+ sequence = ir_sequence_obj.get(cr, uid, 'stock.lot.serial')
+ prodlot_id = prodlot_obj.create(cr, uid, {'name': sequence}, {'product_id': move.product_id.id})
uos_qty = quantity / move_qty * move.product_uos_qty
uos_qty_rest = quantity_rest / move_qty * move.product_uos_qty
default_val = {
@@ -72,6 +76,7 @@ class stock_split_into(osv.osv_memory):
current_move = move_obj.copy(cr, uid, move.id, default_val)
new_move.append(current_move)
update_val['product_qty'] = quantity_rest
+ update_val['prodlot_id'] = prodlot_id
update_val['product_uos_qty'] = uos_qty_rest
move_obj.write(cr, uid, [move.id], update_val)
return {}
diff --git a/addons/stock/wizard/stock_splitinto_view.xml b/addons/stock/wizard/stock_splitinto_view.xml
index 116511b8755..50555eea926 100644
--- a/addons/stock/wizard/stock_splitinto_view.xml
+++ b/addons/stock/wizard/stock_splitinto_view.xml
@@ -8,7 +8,8 @@
form