From d878f170b30bbd3e70fd2eb6daaace0e0fd9a9e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 7 Nov 2008 14:33:59 +0100 Subject: [PATCH] Add purchase quantity and unit_price on stock move --- purchase.py | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++- purchase.xml | 38 +++++++++++++++++++++-- 2 files changed, 123 insertions(+), 3 deletions(-) diff --git a/purchase.py b/purchase.py index 803665630f..bf469aac4a 100644 --- a/purchase.py +++ b/purchase.py @@ -1390,7 +1390,37 @@ class Move(OSV): }) purchase = fields.Function('get_purchase', type='many2one', relation='purchase.purchase', string='Purchase', - fnct_search='search_purchase', select=1) + fnct_search='search_purchase', select=1, states={ + 'invisible': "type != 'input'", + }) + purchase_quantity = fields.Function('get_purchase_fields', + type='float', digits="(16, unit_digits)", + string='Purchase Quantity', + states={ + 'invisible': "type != 'input'", + }) + purchase_unit = fields.Function('get_purchase_fields', + type='many2one', relation='product.uom', + string='Purchase Unit', + states={ + 'invisible': "type != 'input'", + }) + purchase_unit_digits = fields.Function('get_purchase_fields', + type='integer', string='Purchase Unit Digits', + states={ + 'invisible': "type != 'input'", + }) + purchase_unit_price = fields.Function('get_purchase_fields', + type='numeric', digits=(16, 4), string='Purchase Unit Price', + states={ + 'invisible': "type != 'input'", + }) + purchase_currency = fields.Function('get_purchase_fields', + type='many2one', relation='currency.currency', + string='Purchase Currency', + states={ + 'invisible': "type != 'input'", + }) supplier = fields.Function('get_supplier', type='many2one', relation='party.party', string='Supplier', fnct_search='search_supplier', select=1) @@ -1425,6 +1455,62 @@ class Move(OSV): i += 1 return args2 + def get_purchase_fields(self, cursor, user, ids, names, arg, context=None): + uom_obj = self.pool.get('product.uom') + currency_obj = self.pool.get('currency.currency') + + res = {} + for name in names: + res[name] = {} + + for move in self.browse(cursor, user, ids, context=context): + for name in res.keys(): + if name[9:] == 'quantity': + res[name][move.id] = 0.0 + elif name[9:] == 'unit_digits': + res[name][move.id] = 2 + else: + res[name][move.id] = False + if move.purchase_line: + for name in res.keys(): + if name[9:] == 'currency': + res[name][move.id] = move.purchase_line.\ + purchase.currency.id + elif name[9:] in ('quantity', 'unit_digits', 'unit_price'): + res[name][move.id] = move.purchase_line[name[9:]] + else: + res[name][move.id] = move.purchase_line[name[9:]].id + + if 'purchase_unit' in res.keys(): + unit_names = {} + for unit_id, unit_name in uom_obj.name_get(cursor, user, + list(set([x for x in res['purchase_unit'].values() if x])), + context=context): + unit_names[unit_id] = (unit_id, unit_name) + for i in res['purchase_unit'].keys(): + if res['purchase_unit'][i] and \ + res['purchase_unit'][i] in unit_names: + res['purchase_unit'][i] = unit_names[ + res['purchase_unit'][i]] + else: + res['purchase_unit'][i] = False + + if 'purchase_currency' in res.keys(): + currency_names = {} + for currency_id, currency_name in currency_obj.name_get(cursor, + user, + list(set([x for x in res['purchase_currency'].values() if x])), + context=context): + currency_names[currency_id] = (currency_id, currency_name) + for i in res['purchase_currency'].keys(): + if res['purchase_currency'][i] and \ + res['purchase_currency'][i] in currency_names: + res['purchase_currency'][i] = currency_names[ + res['purchase_currency'][i]] + else: + res['purchase_currency'][i] = False + return res + def get_supplier(self, cursor, user, ids, name, arg, context=None): party_obj = self.pool.get('party.party') diff --git a/purchase.xml b/purchase.xml index dd7c8c63ba..8225713716 100644 --- a/purchase.xml +++ b/purchase.xml @@ -752,9 +752,8 @@ this repository contains the full copyright notices and license terms. --> - - @@ -762,6 +761,41 @@ this repository contains the full copyright notices and license terms. --> + + stock.move + + + + + + + + + + + + + + ]]> + + + Suppliers purchase.open_supplier