Merge lp:~9-pierre-6/stock-logistic-tracking/stock-logistic-tracking-prodlot-copy into lp:stock-logistic-tracking/6.1

Proposed by Pierre Monod
Status: Merged
Merged at revision: 14
Proposed branch: lp:~9-pierre-6/stock-logistic-tracking/stock-logistic-tracking-prodlot-copy
Merge into: lp:stock-logistic-tracking/6.1
Diff against target: 90 lines (+11/-27)
1 file modified
stock_tracking_extended/stock_tracking.py (+11/-27)
To merge this branch: bzr merge lp:~9-pierre-6/stock-logistic-tracking/stock-logistic-tracking-prodlot-copy
Reviewer Review Type Date Requested Status
Niels Huylebroeck (community) Abstain
Guewen Baconnier @ Camptocamp Approve
Review via email: mp+139204@code.launchpad.net

Description of the change

Improvement:
Update on the copy of a production lot.
The move_ids are set to 0 as this is a new production lot.
The tracking_id is set to null as well.

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

The copy method looks good to me, and the cleaning on the comments is welcome.

review: Approve
Revision history for this message
Niels Huylebroeck (red15) wrote :

Personally I like the copy function to be more as this:

def copy(...):
    if 'state' not in defaults:
        defaults['state'] = 'draft'
    if '...' not in defaults:
        defaults['...'] = '...'

This allows custom code to still inject new defaults without having to do another write after the copy method call.
This is something I've long tried OpenERP to convince of because it can create bad code when you want to copy something and specify new defaults on the fly (which get overwritten in the copy method you proposed).

review: Abstain

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'stock_tracking_extended/stock_tracking.py'
2--- stock_tracking_extended/stock_tracking.py 2012-11-22 08:05:25 +0000
3+++ stock_tracking_extended/stock_tracking.py 2012-12-11 14:02:21 +0000
4@@ -110,8 +110,6 @@
5 if pack.parent_id:
6 if pack.parent_id and pack.parent_id != 'open':
7 self.write(cr, uid, [pack.parent_id.id], {'state': 'open'}, context=context)
8-# allowed = False
9-# raise osv.except_osv(_('Not allowed !'),_('You can\'t re-open this pack because the parent pack is close'))
10 if allowed:
11 for child in pack.child_ids:
12 if child.state == 'open':
13@@ -195,7 +193,6 @@
14 'product_id': fields.many2one('product.product', 'Product'),
15 'quantity': fields.float('Quantity'),
16 'tracking_id': fields.many2one('stock.tracking', 'Tracking'),
17-# 'tracking_history_id': fields.many2one('stock.tracking.history', 'Tracking History'),
18 }
19
20 product_stock_tracking()
21@@ -211,7 +208,6 @@
22 'product_id': fields.related('serial_id', 'product_id', type='many2one', relation='product.product', string='Product'),
23 'quantity': fields.float('Quantity'),
24 'tracking_id': fields.many2one('stock.tracking', 'Tracking'),
25-# 'tracking_history_id': fields.many2one('stock.tracking.history', 'Tracking History'),
26 }
27
28 serial_stock_tracking()
29@@ -221,34 +217,13 @@
30 _name = "stock.tracking.history"
31
32 def _get_types(self, cr, uid, context={}):
33-# res = [('pack_in','Add parent'),('pack_out','Unlink parent'),('move','Move')]
34 res = []
35 return res
36
37-# def hierarchy_ids(self, tracking):
38-# result_list = [tracking]
39-# for child in tracking.child_ids:
40-# result_list.extend(self.hierarchy_ids(child))
41-# return result_list
42-#
43-# def _get_child_products(self, cr, uid, ids, field_name, arg, context=None):
44-# packs = self.browse(cr, uid, ids)
45-# res = {}
46-# for pack in packs:
47-# res[pack.id] = []
48-# childs = self.hierarchy_ids(pack)
49-# for child in childs:
50-# for prod in child.product_ids:
51-# res[pack.id].append(prod.id)
52-# return res
53
54 _columns = {
55 'tracking_id': fields.many2one('stock.tracking', 'Pack', required=True),
56 'type': fields.selection(_get_types, 'Type'),
57-# 'product_ids': fields.one2many('product.stock.tracking', 'tracking_history_id', 'Products'),
58-# 'child_product_ids': fields.function(_get_child_products, method=True, type='one2many', obj='product.stock.tracking', string='Child Products'),
59-# 'parent_hist_id': fields.many2one('stock.tracking.history', 'Parent history pack'),
60-# 'child_ids': fields.one2many('stock.tracking.history', 'parent_hist_id', 'Child history pack'),
61 }
62
63 _rec_name = "tracking_id"
64@@ -261,7 +236,17 @@
65 _columns = {
66 'tracking_id': fields.many2one('stock.tracking', 'pack'),
67 }
68-
69+ def copy(self, cr, uid, id, default=None, context=None):
70+ if default is None:
71+ default = {}
72+ default.update({
73+ 'state': 'draft',
74+ 'shipped': False,
75+ 'tracking_id': False,
76+ 'move_ids': [],
77+ })
78+ return super(stock_production_lot, self).copy(cr, uid, id, default, context=context)
79+
80 stock_production_lot()
81
82 class product_category(osv.osv):
83@@ -282,7 +267,6 @@
84 _inherit = 'stock.move'
85 _columns = {
86 'move_ori_id': fields.many2one('stock.move', 'Origin Move', select=True),
87-# 'cancel_cascade': fields.boolean('Cancel Cascade', help='If checked, when this move is cancelled, cancel the linked move too')
88 }
89
90 def write(self, cr, uid, ids, vals, context=None):

Subscribers

People subscribed via source and target branches