From bf62bbcc7b931bec16b1b500f7ca6f1a7841ed7d Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Wed, 24 Feb 2010 16:25:03 +0530 Subject: [PATCH 1/3] [IMP] stock: improve consume and split move method bzr revid: hmo@tinyerp.com-20100224105503-to6ed1t4dm250tm6 --- addons/stock/stock.py | 70 +++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index c69e1408325..117e60853fe 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1432,26 +1432,27 @@ class stock_move(osv.osv): return super(stock_move, self).unlink( cr, uid, ids, context=context) - def split_lines(self, cr, uid, ids, quantity, split_by_qty=1, prefix=False, with_lot=True, context=None): + def _create_lot(self, cr, uid, ids, product_id, prefix=False): prodlot_obj = self.pool.get('stock.production.lot') ir_sequence_obj = self.pool.get('ir.sequence') + sequence = ir_sequence_obj.get(cr, uid, 'stock.lot.serial') + if not sequence: + raise wizard.except_wizard(_('Error!'), _('No production sequence defined')) + prodlot_id = prodlot_obj.create(cr, uid, {'name': sequence, 'prefix': prefix}, {'product_id': product_id}) + prodlot = prodlot_obj.browse(cr, uid, prodlot_id) + ref = ','.join(map(lambda x:str(x),ids)) + if prodlot.ref: + ref = '%s, %s' % (prodlot.ref, ref) + prodlot_obj.write(cr, uid, [prodlot_id], {'ref': ref}) + return prodlot_id + + def split_lines(self, cr, uid, ids, quantity, split_by_qty=1, prefix=False, with_lot=True, context=None): + if quantity <= 0: raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !')) - res = [] - - def _create_lot(move_id, product_id): - sequence = ir_sequence_obj.get(cr, uid, 'stock.lot.serial') - if not sequence: - raise wizard.except_wizard(_('Error!'), _('No production sequence defined')) - prodlot_id = prodlot_obj.create(cr, uid, {'name': sequence, 'prefix': prefix}, {'product_id': product_id}) - prodlot = prodlot_obj.browse(cr, uid, prodlot_id) - ref = '%d' % (move_id) - if prodlot.ref: - ref = '%s, %s' % (prodlot.ref, ref) - prodlot_obj.write(cr, uid, [prodlot_id], {'ref': ref}) - return prodlot_id + res = [] for move in self.browse(cr, uid, ids): if split_by_qty <= 0 or quantity == 0: @@ -1466,24 +1467,32 @@ class stock_move(osv.osv): 'product_qty': split_by_qty, 'product_uos_qty': uos_qty, } - for idx in range(int(quantity//split_by_qty)): - current_move = self.copy(cr, uid, move.id, {'state': move.state}) + for idx in range(int(quantity//split_by_qty)): + if not idx and move.product_qty<=quantity: + current_move = move.id + else: + current_move = self.copy(cr, uid, move.id, {'state': move.state}) res.append(current_move) if with_lot: - update_val['prodlot_id'] = _create_lot(current_move, move.product_id.id) + update_val['prodlot_id'] = self._create_lot(cr, uid, [current_move], move.product_id.id) self.write(cr, uid, [current_move], update_val) - if quantity_rest > 0: + if quantity_rest > 0: + idx = int(quantity//split_by_qty) update_val['product_qty'] = quantity_rest - update_val['product_uos_qty'] = uos_qty_rest - current_move = self.copy(cr, uid, move.id, {'state': move.state}) + update_val['product_uos_qty'] = uos_qty_rest + if not idx and move.product_qty<=quantity: + current_move = move.id + else: + current_move = self.copy(cr, uid, move.id, {'state': move.state}) + res.append(current_move) if with_lot: - update_val['prodlot_id'] = _create_lot(current_move, move.product_id.id) + update_val['prodlot_id'] = self._create_lot(cr, uid, [current_move], move.product_id.id) self.write(cr, uid, [current_move], update_val) return res @@ -1519,7 +1528,7 @@ class stock_move(osv.osv): default_val.update({'location_dest_id':location_dest_id}) if location_id: default_val.update({'location_id':location_id}) - + if move.product_id.track_production and location_id: res += self.split_lines(cr, uid, [move.id], quantity, split_by_qty=1, context=context) else: @@ -1533,13 +1542,16 @@ class stock_move(osv.osv): else: quantity_rest = quantity - uos_qty_rest = uos_qty - res += [move.id] - - update_val = {} - update_val['product_qty'] = quantity_rest - update_val['product_uos_qty'] = uos_qty_rest - self.write(cr, uid, [move.id], update_val) + uos_qty_rest = uos_qty + + if move.product_id.track_production and location_id: + res += self.split_lines(cr, uid, [move.id], quantity_rest, split_by_qty=1, context=context) + else: + res += [move.id] + update_val = {} + update_val['product_qty'] = quantity_rest + update_val['product_uos_qty'] = uos_qty_rest + self.write(cr, uid, [move.id], update_val) if consume: self.action_done(cr, uid, res) From d06f4a6c874b3f9000a8b6e11e1354086f155cab Mon Sep 17 00:00:00 2001 From: "mra (Open ERP)" Date: Wed, 24 Feb 2010 16:30:40 +0530 Subject: [PATCH 2/3] [FIX] account_tax_include: product_id_change on invoice line arguments bzr revid: mra@tinyerp.com-20100224110040-45nvckdigr6dx2at --- .../account_tax_include/invoice_tax_incl.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/addons/account_tax_include/invoice_tax_incl.py b/addons/account_tax_include/invoice_tax_incl.py index d4255bb96a9..94e2871da84 100644 --- a/addons/account_tax_include/invoice_tax_incl.py +++ b/addons/account_tax_include/invoice_tax_incl.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## @@ -36,7 +36,7 @@ class account_invoice(osv.osv): _defaults = { 'price_type': lambda *a: 'tax_excluded', } - + def refund(self, cr, uid, ids, date=None, period_id=None, description=None): map_old_new = {} refund_ids = [] @@ -44,12 +44,12 @@ class account_invoice(osv.osv): new_id = super(account_invoice,self).refund(cr, uid, ids, date=date, period_id=period_id, description=description) refund_ids += new_id map_old_new[old_inv_id] = new_id[0] - + for old_inv_id in map_old_new.keys(): old_inv_record = self.read(cr, uid, [old_inv_id], ['price_type'])[0]['price_type'] self.write(cr, uid, [map_old_new[old_inv_id]], {'price_type' : old_inv_record}) return refund_ids - + account_invoice() class account_invoice_line(osv.osv): @@ -156,16 +156,16 @@ class account_invoice_line(osv.osv): else: return super(account_invoice_line, self).product_id_change_unit_price_inv(cr, uid, tax_id, price_unit, qty, address_invoice_id, product, partner_id, context=context) - def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, context=None): + def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None): # note: will call product_id_change_unit_price_inv with context... - # Temporary trap, for bad context that came from koo: + # Temporary trap, for bad context that came from koo: # if isinstance(context, str): # print "str context:", context ctx = (context and context.copy()) or {} ctx.update({'price_type': ctx.get('price_type','tax_excluded')}) - return super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, address_invoice_id, context=ctx) + return super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, address_invoice_id, currency_id=currency_id, context=ctx) account_invoice_line() class account_invoice_tax(osv.osv): @@ -180,7 +180,7 @@ class account_invoice_tax(osv.osv): cur_obj = self.pool.get('res.currency') cur = inv.currency_id company_currency = inv.company_id.currency_id.id - + for line in inv.invoice_line: data = self.pool.get('account.invoice.line')._amount_line2(cr, uid, [line.id], [], [], context)[line.id] for tax in data['data']: @@ -218,7 +218,7 @@ class account_invoice_tax(osv.osv): t['amount'] = cur_obj.round(cr, uid, cur, t['amount']) t['base_amount'] = cur_obj.round(cr, uid, cur, t['base_amount']) t['tax_amount'] = cur_obj.round(cr, uid, cur, t['tax_amount']) - + return tax_grouped account_invoice_tax() From e6b584bf400f3f49512e98cfecb89dffb5a274aa Mon Sep 17 00:00:00 2001 From: "mra (Open ERP)" Date: Wed, 24 Feb 2010 16:33:48 +0530 Subject: [PATCH 3/3] [ADD] membership: added wizard which will list all unpaid partners for given membership product bzr revid: mra@tinyerp.com-20100224110348-0rfub41fshu1y2ir --- addons/membership/membership_wizard.xml | 11 +++ addons/membership/wizard/__init__.py | 5 +- .../wizard/unpaid_partner_invoice.py | 86 +++++++++++++++++++ 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 addons/membership/wizard/unpaid_partner_invoice.py diff --git a/addons/membership/membership_wizard.xml b/addons/membership/membership_wizard.xml index e4400393de6..67068ff151d 100644 --- a/addons/membership/membership_wizard.xml +++ b/addons/membership/membership_wizard.xml @@ -2,5 +2,16 @@ + + + + diff --git a/addons/membership/wizard/__init__.py b/addons/membership/wizard/__init__.py index 9f5d3dc14af..bffa2fb6a21 100644 --- a/addons/membership/wizard/__init__.py +++ b/addons/membership/wizard/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # @@ -15,10 +15,11 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## import invoice_membership +import unpaid_partner_invoice # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/membership/wizard/unpaid_partner_invoice.py b/addons/membership/wizard/unpaid_partner_invoice.py new file mode 100644 index 00000000000..20585f6570c --- /dev/null +++ b/addons/membership/wizard/unpaid_partner_invoice.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import wizard +import pooler + +wizard_arch= """ +
+ +""" + +def _invoice_membership(self, cr, uid, data, context): + pool = pooler.get_pool(cr.dbname) + partners = [] + cr.execute('''select p.id from res_partner as p \ + left join account_invoice as i on p.id=i.partner_id \ + left join account_invoice_line as il on i.id=il.invoice_id \ + left join product_product as pr on pr.id=il.product_id \ + where i.state = 'open' and pr.id=%s \ + group by p.id''' % (data['form']['product'])) + map(lambda x: partners.append(x[0]),cr.fetchall()) + result = pool.get('ir.model.data')._get_id(cr, uid, 'base', 'view_res_partner_filter') + res = pool.get('ir.model.data').read(cr, uid, result, ['res_id']) + value = { + 'domain': [('id', 'in', partners)], + 'name': 'Unpaid Partners', + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'res.partner', + 'type': 'ir.actions.act_window', + 'res_id' : partners, + 'search_view_id' : res['res_id'] + } + return value + +class wizard_unpaid_inv(wizard.interface): + + states = { + 'init' : { + 'actions' : [], + 'result' : { + 'type' : 'form', + 'arch' : wizard_arch, + 'fields' : { + 'product': { + 'string': 'Membership product', + 'type': 'many2one', + 'relation': 'product.product', + 'help': 'Select Membership product', + 'required': True + }, + }, + 'state' : [('end', 'Cancel'),('ok', 'Unpaid Partners') ]} + }, + 'ok' : { + 'actions' : [], + 'result' : {'type' : 'action', 'action': _invoice_membership, 'state' : 'end'}, + }, + + } + +wizard_unpaid_inv("wizard.invoice.membership.unpaid") + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: