diff --git a/addons/point_of_sale/wizard/pos_return.py b/addons/point_of_sale/wizard/pos_return.py index 810ef86ec7b..f86b96b04d5 100644 --- a/addons/point_of_sale/wizard/pos_return.py +++ b/addons/point_of_sale/wizard/pos_return.py @@ -24,9 +24,25 @@ from osv import osv,fields from tools.translate import _ import time +class pos_return_memory(osv.osv_memory): + _name = "pos.return.memory" + _rec_name = 'product_id' + _columns = { + 'product_id' : fields.many2one('product.product', string="Product", required=True), + 'quantity' : fields.float("Quantity", required=True), + 'pos_moves_id' : fields.many2one('pos.return', string="Move"), + 'line_id': fields.integer('Line Id'), + } + +pos_return_memory() + + class pos_return(osv.osv_memory): _name = 'pos.return' _description = 'Point of sale return' + _columns = { + 'pos_moves_ids' : fields.one2many('pos.return.memory', 'pos_moves_id', 'Moves'), + } def default_get(self, cr, uid, fields, context=None): """ @@ -41,38 +57,22 @@ class pos_return(osv.osv_memory): @return: A dictionary which of fields with values. """ - res = super(pos_return, self).default_get(cr, uid, fields, context=context) order_obj = self.pool.get('pos.order') if context is None: context={} active_ids = context.get('active_ids') + result=[] + memory={} for order in order_obj.browse(cr, uid, active_ids, context=context): for line in order.lines: - if 'return%s'%(line.id) in fields: - res['return%s'%(line.id)] = line.qty - return res - - def view_init(self, cr, uid, fields_list, context=None): - """ - Creates view dynamically and adding fields at runtime. - @param self: The object pointer. - @param cr: A database cursor - @param uid: ID of the user currently logged in - @param context: A standard dictionary - @return: New arch of view with new columns. - """ - res = super(pos_return, self).view_init(cr, uid, fields_list, context=context) - order_obj=self.pool.get('pos.order') - if context is None: - context={} - - active_ids=context.get('active_ids') - for order in order_obj.browse(cr, uid, active_ids, context=context): - for line in order.lines: - if 'return%s'%(line.id) not in self._columns: - self._columns['return%s'%(line.id)] = fields.float("Quantity") - + memory = { + 'product_id' : line.product_id.id, + 'quantity' : line.qty, + 'line_id':line.id + } + result.append(memory) + res.update({'pos_moves_ids': result}) return res def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False,submenu=False): @@ -99,23 +99,19 @@ class pos_return(osv.osv_memory): if active_id: _moves_arch_lst="""