|
| 1 | +# -*- encoding: utf-8 -*- |
| 2 | +############################################################################## |
| 3 | +# For copyright and license notices, see __openerp__.py file in root directory |
| 4 | +############################################################################## |
| 5 | +from openerp import models, api |
| 6 | + |
| 7 | + |
| 8 | +class sale_order(models.Model): |
| 9 | + _inherit = 'sale.order' |
| 10 | + |
| 11 | + @api.model |
| 12 | + def create(self, vals): |
| 13 | + result = super(sale_order, self).create(vals) |
| 14 | + result.expand_packs() |
| 15 | + return result |
| 16 | + |
| 17 | + @api.multi |
| 18 | + def write(self, vals): |
| 19 | + result = super(sale_order, self).write(vals) |
| 20 | + if vals.get('order_line'): |
| 21 | + self.expand_packs() |
| 22 | + return result |
| 23 | + |
| 24 | + # def copy(self, cr, uid, id, default={}, context=None): |
| 25 | + # line_obj = self.pool.get('sale.order.line') |
| 26 | + # result = super(sale_order, self).copy(cr, uid, id, default, context) |
| 27 | + # sale = self.browse(cr, uid, result, context) |
| 28 | + # for line in sale.order_line: |
| 29 | + # if line.pack_parent_line_id: |
| 30 | + # line_obj.unlink(cr, uid, [line.id], context) |
| 31 | + # self.expand_packs(cr, uid, sale.id, context) |
| 32 | + # return result |
| 33 | + |
| 34 | + @api.one |
| 35 | + def expand_packs(self): |
| 36 | + """ |
| 37 | + """ |
| 38 | + pack_lines = self.order_line.filtered( |
| 39 | + lambda l: l.state == 'draft' and |
| 40 | + l.product_id.pack and |
| 41 | + not l.product_id.sale_order_pack) |
| 42 | + print 'pack_lines', pack_lines |
| 43 | + while pack_lines: |
| 44 | + pack_lines = pack_lines.update_pack_lines() |
| 45 | + |
| 46 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
0 commit comments