From abf2c94f97377144db7c6860d7212282065c29a8 Mon Sep 17 00:00:00 2001 From: Harshad Modi Date: Fri, 26 Sep 2008 15:55:10 +0530 Subject: [PATCH] Improvement : * Purchase Order from scheduler: use tax from partner if any. * Report Purchase Order: if address, it uses the name of the company and the address of the customer. Change to use the name of the customer. * Print Packing List: don't display the lines with state=confirmed (only assigned) * When invoice on picking: if I generate invoice on the sale order, it must set the pickings as invoiced * When invoicing from picking: sale order lines stays as 'To be Invoiced' * make new method to get partner property field data same like getting address on partner module and fetch property using this function on needed on onchange partner on sale, purchase module * on delivery module, take taxes from partner if partner has default tax other wise take from delivery product when creation invoice line * on overdue payment report, tel no is display with company invoice address's tel no * Purchase Order from scheduler : assign note of purchase order line with product purchase description * product model : all description should be translatable * fixed bug : on scheduler.py file on mrp module ( got error when select Auto orderpoint on scheduling wizard) * fixed bug : on product available function on stock module ( got error when call it with field_name=None ) bzr revid: hmo@tinyerp.com-20080926102510-nrjwloh0ojkl4hgn --- addons/account/report/overdue.py | 15 ++++++++ addons/account/report/overdue.rml | 2 +- addons/delivery/stock.py | 23 ++++++++++-- addons/delivery/wizard/delivery_sale_order.py | 24 ++++++++++-- addons/mrp/mrp.py | 30 +++++++++++++-- addons/mrp/schedulers.py | 4 +- addons/product/product.py | 6 +-- addons/purchase/purchase.py | 37 ++++++++++--------- addons/purchase/report/order.rml | 4 +- addons/sale/sale.py | 18 ++++++--- addons/stock/product.py | 4 +- addons/stock/report/picking.rml | 2 +- addons/stock/stock.py | 5 ++- addons/stock/stock_view.xml | 1 + 14 files changed, 131 insertions(+), 44 deletions(-) diff --git a/addons/account/report/overdue.py b/addons/account/report/overdue.py index c37e2c98363..bf456e8256f 100644 --- a/addons/account/report/overdue.py +++ b/addons/account/report/overdue.py @@ -42,6 +42,7 @@ class Overdue(report_sxw.rml_parse): 'time' : time, 'adr_get' : self._adr_get, 'getLines' : self._lines_get, + 'tel_get' : self._tel_get, }) def _adr_get(self, partner, type): @@ -51,6 +52,20 @@ class Overdue(report_sxw.rml_parse): adr_id = addresses and addresses[type] or False return adr_id and res_partner_address.read(self.cr, self.uid, [adr_id])[0] or False + def _tel_get(self,partner): + if not partner: + return False + res_partner_address = pooler.get_pool(self.cr.dbname).get('res.partner.address') + res_partner = pooler.get_pool(self.cr.dbname).get('res.partner') + addresses = res_partner.address_get(self.cr, self.uid, [partner.id], ['invoice']) + adr_id = addresses and addresses['invoice'] or False + if adr_id: + adr=res_partner_address.read(self.cr, self.uid, [adr_id])[0] + return adr['phone'] + else: + return partner.address and partner.address[0].phone or False + return False + def _lines_get(self, partner): moveline_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') movelines = moveline_obj.search(self.cr, self.uid, diff --git a/addons/account/report/overdue.rml b/addons/account/report/overdue.rml index fc6dde92f50..f9f213f0d89 100644 --- a/addons/account/report/overdue.rml +++ b/addons/account/report/overdue.rml @@ -110,7 +110,7 @@ - Would your payment have been carried out after this mail was sent, please consider the present one as void. Do not hesitate to contact our accounting departement at +32 81 81 37 00. + Would your payment have been carried out after this mail was sent, please consider the present one as void. Do not hesitate to contact our accounting departement at [[ tel_get(company.partner_id) ]]. diff --git a/addons/delivery/stock.py b/addons/delivery/stock.py index 1a439c45ec2..d76b711e8d8 100644 --- a/addons/delivery/stock.py +++ b/addons/delivery/stock.py @@ -82,6 +82,25 @@ class stock_picking(osv.osv): if not account_id: account_id = picking.carrier_id.product_id.categ_id\ .property_account_income_categ.id + + taxes = self.pool.get('account.tax').browse(cursor, user, + [x.id for x in picking.carrier_id.product_id.taxes_id]) + taxep = None + partner_id=picking.address_id.partner_id and picking.address_id.partner_id.id or False + if partner_id: + taxep_id = self.pool.get('res.partner').property_get(cursor, user,partner_id,property_pref=['property_account_tax']).get('property_account_tax',False) + if taxep_id: + taxep=self.pool.get('account.tax').browse(cursor, user,taxep_id) + if not taxep or not taxep.id: + taxes_ids = [x.id for x in picking.carrier_id.product_id.taxes_id] + else: + res5 = [taxep.id] + for t in taxes: + if not t.tax_group==taxep.tax_group: + res5.append(t.id) + taxes_ids = res5 + + invoice_line_obj.create(cursor, user, { 'name': picking.carrier_id.name, 'invoice_id': invoice.id, @@ -90,9 +109,7 @@ class stock_picking(osv.osv): 'account_id': account_id, 'price_unit': price, 'quantity': 1, - 'invoice_line_tax_id': [(6, 0, - [x.id for x in (picking.carrier_id.product_id.taxes_id - or [])])], + 'invoice_line_tax_id': [(6, 0,taxes_ids)], }) return result diff --git a/addons/delivery/wizard/delivery_sale_order.py b/addons/delivery/wizard/delivery_sale_order.py index 8b56145639c..54a48f4ac54 100644 --- a/addons/delivery/wizard/delivery_sale_order.py +++ b/addons/delivery/wizard/delivery_sale_order.py @@ -65,16 +65,34 @@ def _delivery_set(self, cr, uid, data, context): grid_id = pooler.get_pool(cr.dbname).get('delivery.carrier').grid_get(cr, uid, [data['form']['carrier_id']],order.partner_shipping_id.id) if not grid_id: raise wizard.except_wizard(_('No grid avaible !'), _('No grid matching for this carrier !')) - grid = pooler.get_pool(cr.dbname).get('delivery.grid').browse(cr, uid, [grid_id])[0] + grid_obj=pooler.get_pool(cr.dbname).get('delivery.grid') + grid = grid_obj.browse(cr, uid, [grid_id])[0] + taxes = pooler.get_pool(cr.dbname).get('account.tax').browse(cr, uid, + [x.id for x in grid.carrier_id.product_id.taxes_id]) + taxep = None + partner_id=order.partner_id and order.partner_id.id or False + if partner_id: + taxep_id = pooler.get_pool(cr.dbname).get('res.partner').property_get(cr, uid,partner_id,property_pref=['property_account_tax']).get('property_account_tax',False) + if taxep_id: + taxep=pooler.get_pool(cr.dbname).get('account.tax').browse(cr, uid,taxep_id) + if not taxep or not taxep.id: + taxes_ids = [x.id for x in grid.carrier_id.product_id.taxes_id] + else: + res5 = [taxep.id] + for t in taxes: + if not t.tax_group==taxep.tax_group: + res5.append(t.id) + taxes_ids = res5 + line_obj.create(cr, uid, { 'order_id': order.id, 'name': grid.carrier_id.name, 'product_uom_qty': 1, 'product_uom': grid.carrier_id.product_id.uom_id.id, 'product_id': grid.carrier_id.product_id.id, - 'price_unit': grid.get_price(cr, uid, grid.id, order, time.strftime('%Y-%m-%d'), context), - 'tax_id': [(6,0,[ x.id for x in grid.carrier_id.product_id.taxes_id])], + 'price_unit': grid_obj.get_price(cr, uid, grid.id, order, time.strftime('%Y-%m-%d'), context), + 'tax_id': [(6,0,taxes_ids)], 'type': 'make_to_stock' }) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 170cefd6fbc..11aad76fc40 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -947,17 +947,41 @@ class mrp_procurement(osv.osv): newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S') - DateTime.RelativeDateTime(days=procurement.product_id.product_tmpl_id.seller_delay or 0.0) newdate = newdate - DateTime.RelativeDateTime(days=company.po_lead) + context.update({'lang':partner.lang}) + product=self.pool.get('product.product').browse(cr,uid,procurement.product_id.id,context=context) + line = { - 'name': procurement.product_id.name, + 'name': product.name, 'product_qty': qty, 'product_id': procurement.product_id.id, 'product_uom': uom_id, 'price_unit': price, - 'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'), - 'taxes_id': [(6, 0, [x.id for x in procurement.product_id.product_tmpl_id.supplier_taxes_id])], + 'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'), 'move_dest_id': res_id, + 'notes':product.description_purchase, } + taxes = self.pool.get('account.tax').browse(cr, uid, + [x.id for x in procurement.product_id.product_tmpl_id.supplier_taxes_id]) + taxep = None + if partner_id: + taxep_id = self.pool.get('res.partner').property_get(cr, uid,partner_id,property_pref=['property_account_supplier_tax']).get('property_account_supplier_tax',False) + if taxep_id: + taxep=self.pool.get('account.tax').browse(cr, uid,taxep_id) + if not taxep or not taxep.id: + taxes_ids = [x.id for x in procurement.product_id.product_tmpl_id.supplier_taxes_id] + else: + res5 = [taxep.id] + for t in taxes: + if not t.tax_group==taxep.tax_group: + res5.append(t.id) + taxes_ids = res5 + + line.update({ + 'taxes_id':[(6,0,taxes_ids)] + }) + + purchase_id = self.pool.get('purchase.order').create(cr, uid, { 'origin': procurement.origin, 'partner_id': partner_id, diff --git a/addons/mrp/schedulers.py b/addons/mrp/schedulers.py index 263d8c915a4..dec3636f3e0 100644 --- a/addons/mrp/schedulers.py +++ b/addons/mrp/schedulers.py @@ -132,7 +132,7 @@ class mrp_procurement(osv.osv): cr.close() return {} - def create_automatic_op(cr, uid, context=None): + def create_automatic_op(self,cr, uid, context=None): if not context: context={} product_obj = self.pool.get('product.product') @@ -192,7 +192,7 @@ class mrp_procurement(osv.osv): offset = 0 ids = [1] if automatic: - create_automatic_op(cr, uid, context=context) + self.create_automatic_op(cr, uid, context=context) while ids: ids=orderpoint_obj.search(cr,uid,[],offset=offset,limit=100) for op in orderpoint_obj.browse(cr, uid, ids): diff --git a/addons/product/product.py b/addons/product/product.py index 6e1e70d3e98..b3a9f77dc41 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -242,9 +242,9 @@ class product_template(osv.osv): _columns = { 'name': fields.char('Name', size=64, required=True, translate=True, select=True), 'product_manager': fields.many2one('res.users','Product Manager'), - 'description': fields.text('Description'), - 'description_purchase': fields.text('Purchase Description'), - 'description_sale': fields.text('Sale Description'), + 'description': fields.text('Description',translate=True), + 'description_purchase': fields.text('Purchase Description',translate=True), + 'description_sale': fields.text('Sale Description',translate=True), 'type': fields.selection([('product','Stockable Product'),('consu', 'Consumable'),('service','Service')], 'Product Type', required=True, help="Will change the way procurements are processed, consumable are stockable products with infinite stock, or without a stock management in the system."), 'supply_method': fields.selection([('produce','Produce'),('buy','Buy')], 'Supply method', required=True, help="Produce will generate production order or tasks, according to the product type. Purchase will trigger purchase orders when requested."), 'sale_delay': fields.float('Customer Lead Time', help="This is the average time between the confirmation of the customer order and the delivery of the finnished products. It's the time you promise to your customers."), diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 26fdf26c953..0c3527b156d 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -227,7 +227,8 @@ class purchase_order(osv.osv): if not part: return {'value':{'partner_address_id': False}} addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['default']) - pricelist = self.pool.get('res.partner').browse(cr, uid, part).property_product_pricelist_purchase.id + pricelist = self.pool.get('res.partner').property_get(cr, uid, + part,property_pref=['property_product_pricelist_purchase']).get('property_product_pricelist_purchase',False) return {'value':{'partner_address_id': addr['default'], 'pricelist_id': pricelist}} def wkf_approve_order(self, cr, uid, ids): @@ -424,10 +425,10 @@ class purchase_order_line(osv.osv): return {'value': {'price_unit': 0.0, 'name':'','notes':'', 'product_uom' : False}, 'domain':{'product_uom':[]}} lang=False if partner_id: - lang=self.pool.get('res.partner').read(cr, uid, [partner_id])[0]['lang'] + lang=self.pool.get('res.partner').read(cr, uid, partner_id)['lang'] context={'lang':lang} - prod = self.pool.get('product.product').read(cr, uid, [product], ['supplier_taxes_id','name','seller_delay','uom_po_id','description_purchase'])[0] + prod = self.pool.get('product.product').read(cr, uid, product, ['supplier_taxes_id','name','seller_delay','uom_po_id','description_purchase'],context=context) prod_uom_po = prod['uom_po_id'][0] if not uom: uom = prod_uom_po @@ -444,21 +445,21 @@ class purchase_order_line(osv.osv): res = {'value': {'price_unit': price, 'name':prod_name, 'taxes_id':prod['supplier_taxes_id'], 'date_planned': dt,'notes':prod['description_purchase'], 'product_uom': uom}} domain = {} - if res['value']['taxes_id']: - taxes = self.pool.get('account.tax').browse(cr, uid, - [x.id for x in product.supplier_taxes_id]) - taxep = None - if partner_id: - taxep = self.pool.get('res.partner').browse(cr, uid, - partner_id).property_account_supplier_tax - if not taxep or not taxep.id: - res['value']['taxes_id'] = [x.id for x in product.taxes_id] - else: - res5 = [taxep.id] - for t in taxes: - if not t.tax_group==taxep.tax_group: - res5.append(t.id) - res['value']['taxes_id'] = res5 + + taxes = self.pool.get('account.tax').browse(cr, uid,prod['supplier_taxes_id']) + taxep = None + if partner_id: + taxep_id = self.pool.get('res.partner').property_get(cr, uid,partner_id,property_pref=['property_account_supplier_tax']).get('property_account_supplier_tax',False) + if taxep_id: + taxep=self.pool.get('account.tax').browse(cr, uid,taxep_id) + if not taxep or not taxep.id: + res['value']['taxes_id'] = [x.id for x in product.taxes_id] + else: + res5 = [taxep.id] + for t in taxes: + if not t.tax_group==taxep.tax_group: + res5.append(t.id) + res['value']['taxes_id'] = res5 res2 = self.pool.get('product.uom').read(cr, uid, [uom], ['category_id']) res3 = self.pool.get('product.uom').read(cr, uid, [prod_uom_po], ['category_id']) diff --git a/addons/purchase/report/order.rml b/addons/purchase/report/order.rml index 26956a2b0bf..60834dbccc9 100644 --- a/addons/purchase/report/order.rml +++ b/addons/purchase/report/order.rml @@ -141,8 +141,8 @@ [[ repeatIn(o.dest_address_id and [o.dest_address_id] or [],'addr') ]] Shipping address : - [[ o.partner_id.title or '' ]] [[ o.partner_id.name ]] - [[ addr.title or '' ]] [[ addr.name ]] + [[ addr.partner_id.title or '' ]][[ addr.partner_id.name ]] + [[ addr.title or '' ]][[ addr.name ]] [[ addr.street ]] [[ addr.street2 or '' ]] [[ addr.zip or '' ]] [[ addr.city or '' ]] diff --git a/addons/sale/sale.py b/addons/sale/sale.py index d7b3d53c88b..1fd812db08b 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -288,8 +288,10 @@ class sale_order(osv.osv): if not part: return {'value':{'partner_invoice_id': False, 'partner_shipping_id':False, 'partner_order_id':False, 'payment_term' : False}} addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['delivery','invoice','contact']) - pricelist = self.pool.get('res.partner').browse(cr, uid, part).property_product_pricelist.id - payment_term = self.pool.get('res.partner').browse(cr, uid, part).property_payment_term.id + pricelist = self.pool.get('res.partner').property_get(cr, uid, + part,property_pref=['property_product_pricelist']).get('property_product_pricelist',False) + payment_term = self.pool.get('res.partner').property_get(cr, uid, + part,property_pref=['property_payment_term']).get('property_payment_term',False) return {'value':{'partner_invoice_id': addr['invoice'], 'partner_order_id':addr['contact'], 'partner_shipping_id':addr['delivery'], 'pricelist_id': pricelist, 'payment_term' : payment_term}} def button_dummy(self, cr, uid, ids, context={}): @@ -357,18 +359,22 @@ class sale_order(osv.osv): for i in o.invoice_ids: if i.state == 'draft': return i.id - + picking_obj=self.pool.get('stock.picking') for val in invoices.values(): if grouped: res = self._make_invoice(cr, uid, val[0][0], reduce(lambda x,y: x + y, [l for o,l in val], [])) for o,l in val: self.write(cr, uid, [o.id], {'state' : 'progress'}) + if o.order_policy=='picking': + picking_obj.write(cr,uid,map(lambda x:x.id,o.picking_ids),{'invoice_state':'invoiced'}) cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%d,%d)', (o.id, res)) else: for order, il in val: res = self._make_invoice(cr, uid, order, il) invoice_ids.append(res) self.write(cr, uid, [order.id], {'state' : 'progress'}) + if order.order_policy=='picking': + picking_obj.write(cr,uid,map(lambda x:x.id,order.picking_ids),{'invoice_state':'invoiced'}) cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%d,%d)', (order.id, res)) return res @@ -830,8 +836,10 @@ class sale_order_line(osv.osv): [x.id for x in product_obj.taxes_id]) taxep = None if partner_id: - taxep = self.pool.get('res.partner').browse(cr, uid, - partner_id).property_account_tax + taxep_id = self.pool.get('res.partner').property_get(cr, uid, + partner_id,property_pref=['property_account_tax']).get('property_account_tax',False) + if taxep_id: + taxep=self.pool.get('account.tax').browse(cr, uid,taxep_id) if not taxep or not taxep.id: result['tax_id'] = [x.id for x in product_obj.taxes_id] else: diff --git a/addons/stock/product.py b/addons/stock/product.py index 0e2db338b9f..aa7eb1c25df 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -132,7 +132,9 @@ class product_product(osv.osv): return res def _get_product_available_func(states, what): - def _product_available(self, cr, uid, ids, field_names=False, arg=False, context={}): + def _product_available(self, cr, uid, ids, field_names=None, arg=False, context={}): + if not field_names: + field_names=[] context.update({ 'states':states, 'what':what diff --git a/addons/stock/report/picking.rml b/addons/stock/report/picking.rml index 9a3cdaf5a64..99beed93900 100644 --- a/addons/stock/report/picking.rml +++ b/addons/stock/report/picking.rml @@ -207,7 +207,7 @@
- [[ repeatIn(picking.move_lines,'move_lines') ]] + [[ repeatIn([line for line in picking.move_lines if (line.state == 'assigned' )],'move_lines') ]] diff --git a/addons/stock/stock.py b/addons/stock/stock.py index ed0ad6bd442..7f824dfd701 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -581,11 +581,11 @@ class stock_picking(osv.osv): res = {} sale_line_obj = self.pool.get('sale.order.line') - for picking in self.browse(cursor, user, ids, context=context): + for picking in self.browse(cursor, user, ids, context=context): if picking.invoice_state != '2binvoiced': continue payment_term_id = False - partner = picking.address_id.partner_id + partner = picking.address_id and picking.address_id.partner_id if type in ('out_invoice', 'out_refund'): account_id = partner.property_account_receivable.id payment_term_id= picking.sale_id.payment_term.id @@ -712,6 +712,7 @@ class stock_picking(osv.osv): self.write(cursor, user, res.keys(), { 'invoice_state': 'invoiced', }, context=context) + print res return res stock_picking() diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index 905ba361fcd..5db7c283517 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -794,6 +794,7 @@ +