From 2397c71f43be22f828a0c8ce528cf3d0536237bf Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 13 May 2013 13:59:42 +0200 Subject: [PATCH] [IMP] Put price computation (price calculation) to action_done and merge separate module in other modules bzr revid: jco@openerp.com-20130513115942-flyx6wiuv79dtgln --- addons/purchase/__openerp__.py | 2 + .../test/fifo_price.yml} | 0 .../test/lifo_price.yml | 0 addons/stock/__init__.py | 1 + addons/stock/security/ir.model.access.csv | 128 +++++++++--------- addons/stock/security/stock_security.xml | 6 + addons/stock/stock.py | 96 +++++++++++-- .../stock_fifo_lifo.py | 15 +- addons/stock/wizard/stock_partial_picking.py | 12 +- addons/stock_fifo_lifo/__init__.py | 24 ---- addons/stock_fifo_lifo/__openerp__.py | 51 ------- .../security/ir.model.access.csv | 3 - .../security/stock_matching_security.xml | 14 -- 13 files changed, 174 insertions(+), 178 deletions(-) rename addons/{stock_fifo_lifo/test/fifolifo_price.yml => purchase/test/fifo_price.yml} (100%) rename addons/{stock_fifo_lifo => purchase}/test/lifo_price.yml (100%) rename addons/{stock_fifo_lifo => stock}/stock_fifo_lifo.py (93%) delete mode 100644 addons/stock_fifo_lifo/__init__.py delete mode 100644 addons/stock_fifo_lifo/__openerp__.py delete mode 100644 addons/stock_fifo_lifo/security/ir.model.access.csv delete mode 100644 addons/stock_fifo_lifo/security/stock_matching_security.xml diff --git a/addons/purchase/__openerp__.py b/addons/purchase/__openerp__.py index 06a12de4624..c8fe369a559 100644 --- a/addons/purchase/__openerp__.py +++ b/addons/purchase/__openerp__.py @@ -78,6 +78,8 @@ Dashboard / Reports for Purchase Management will include: 'test/ui/duplicate_order.yml', 'test/ui/delete_order.yml', 'test/average_price.yml', + 'test/fifo_price.yml', + 'test/lifo_price.yml' ], 'demo': [ 'purchase_order_demo.yml', diff --git a/addons/stock_fifo_lifo/test/fifolifo_price.yml b/addons/purchase/test/fifo_price.yml similarity index 100% rename from addons/stock_fifo_lifo/test/fifolifo_price.yml rename to addons/purchase/test/fifo_price.yml diff --git a/addons/stock_fifo_lifo/test/lifo_price.yml b/addons/purchase/test/lifo_price.yml similarity index 100% rename from addons/stock_fifo_lifo/test/lifo_price.yml rename to addons/purchase/test/lifo_price.yml diff --git a/addons/stock/__init__.py b/addons/stock/__init__.py index 0f1e96a9c67..af34462f6d6 100644 --- a/addons/stock/__init__.py +++ b/addons/stock/__init__.py @@ -25,5 +25,6 @@ import product import report import wizard import res_config +import stock_fifo_lifo # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/security/ir.model.access.csv b/addons/stock/security/ir.model.access.csv index d89354c5be3..d3d38091b9f 100644 --- a/addons/stock/security/ir.model.access.csv +++ b/addons/stock/security/ir.model.access.csv @@ -1,63 +1,65 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_stock_incoterms_all,stock.incoterms all,model_stock_incoterms,,1,0,0,0 -access_stock_incoterms_manager,stock.incoterms manager,model_stock_incoterms,stock.group_stock_manager,1,1,1,1 -access_stock_warehouse_manager,stock.warehouse.manager,model_stock_warehouse,stock.group_stock_manager,1,1,1,1 -access_stock_warehouse_user,stock.warehouse.user,model_stock_warehouse,base.group_user,1,0,0,0 -access_stock_location__partner_manager,stock.location.partner.manager,model_stock_location,base.group_partner_manager,1,1,1,1 -access_stock_location_manager,stock.location.manager,model_stock_location,stock.group_stock_manager,1,1,1,1 -access_stock_location_user,stock.location.user,model_stock_location,base.group_user,1,0,0,0 -access_stock_journal_user,stock.journal.user,model_stock_journal,base.group_user,1,0,0,0 -access_stock_journal_manager,stock.journal.manager,model_stock_journal,stock.group_stock_manager,1,1,1,1 -access_stock_tracking_user,stock.tracking user,model_stock_tracking,stock.group_stock_user,1,1,1,1 -access_stock_tracking_manager,stock.tracking manager,model_stock_tracking,stock.group_stock_manager,1,0,0,0 -access_stock_tracking_sales_user,stock.tracking sales.user,model_stock_tracking,base.group_sale_salesman,1,1,1,0 -access_stock_picking_user,stock.picking user,model_stock_picking,stock.group_stock_user,1,1,1,1 -access_stock_picking_in_user,stock.picking.in,model_stock_picking_in,stock.group_stock_user,1,1,1,1 -access_stock_picking_out_user,stock.picking.out,model_stock_picking_out,stock.group_stock_user,1,1,1,1 -access_stock_picking_manager,stock.picking manager,model_stock_picking,stock.group_stock_manager,1,1,0,0 -access_stock_picking_in_manager,stock.picking.in manager,model_stock_picking_in,stock.group_stock_manager,1,0,0,0 -access_stock_picking_out_manager,stock.picking.out manager,model_stock_picking_out,stock.group_stock_manager,1,0,0,0 -access_stock_production_lot_manager,stock.production.lot manager,model_stock_production_lot,stock.group_stock_manager,1,0,0,0 -access_stock_production_lot_user,stock.production.lot user,model_stock_production_lot,stock.group_stock_user,1,1,1,1 -access_stock_production_lot_revision,stock.production.lot.revision,model_stock_production_lot_revision,stock.group_stock_user,1,1,1,1 -access_stock_move_manager,stock.move manager,model_stock_move,stock.group_stock_manager,1,1,1,1 -access_stock_move_user,stock.move user,model_stock_move,stock.group_stock_user,1,1,1,0 -access_stock_inventory_user,stock.inventory user,model_stock_inventory,stock.group_stock_user,1,1,1,0 -access_stock_inventory_manager,stock.inventory manager,model_stock_inventory,stock.group_stock_manager,1,1,1,1 -access_stock_inventory_line_user,stock.inventory.line user,model_stock_inventory_line,stock.group_stock_user,1,1,1,0 -access_stock_inventory_line_manager,stock.inventory.line manager,model_stock_inventory_line,stock.group_stock_manager,1,1,1,1 -access_stock_report_prodlots,stock.report.prodlots,model_stock_report_prodlots,stock.group_stock_manager,1,0,0,0 -access_stock_location_sale_manager,stock.location sale manager,model_stock_location,base.group_sale_manager,1,0,0,0 -access_stock_location_stock_manager,stock.location stock manager,model_stock_location,stock.group_stock_manager,1,0,0,0 -access_stock_lines_date_user,report.stock.lines.date user,model_report_stock_lines_date,stock.group_stock_user,1,0,0,0 -access_stock_lines_date_manager,report.stock.lines.date manager,model_report_stock_lines_date,stock.group_stock_manager,1,1,1,1 -access_stock_report_tracklots,stock.report.tracklots,model_stock_report_tracklots,stock.group_stock_user,1,1,1,1 -access_report_stock_move_user,report.stock.move user,model_report_stock_move,stock.group_stock_user,1,0,0,0 -access_report_stock_move_manager,report.stock.move manager,model_report_stock_move,stock.group_stock_manager,1,1,1,1 -access_report_stock_inventory_user,report.stock.inventory user,model_report_stock_inventory,stock.group_stock_user,1,1,1,1 -access_product_product_stock_user,product_product_stock_user,product.model_product_product,stock.group_stock_user,1,1,0,0 -access_product_template_stock_user,product.template stock user,product.model_product_template,stock.group_stock_user,1,1,0,0 -access_account_invoice_user,account.invoice stock user,account.model_account_invoice,stock.group_stock_user,1,1,1,0 -access_account_invoice_line_user,account.invoice.line stock user,account.model_account_invoice_line,stock.group_stock_user,1,1,1,0 -access_account_invoice_tax_user,account.invoice.tax stock user,account.model_account_invoice_tax,stock.group_stock_user,1,1,1,0 -access_account_journal_user,account.journal stock user,account.model_account_journal,stock.group_stock_user,1,0,0,0 -access_account_fiscalyear,account.fiscalyear stock user,account.model_account_fiscalyear,stock.group_stock_user,1,0,0,0 -access_product_pricelist_item_sale_manager,product.pricelist.item salemanager,product.model_product_pricelist_item,base.group_sale_manager,1,1,1,1 -access_product_uom_categ_stock_manager,product.uom.categ stock_manager,product.model_product_uom_categ,stock.group_stock_manager,1,1,1,1 -access_product_uom_stock_manager,product.uom stock_manager,product.model_product_uom,stock.group_stock_manager,1,1,1,1 -access_product_ul_stock_manager,product.ul stock_manager,product.model_product_ul,stock.group_stock_manager,1,1,1,1 -access_product_category_stock_manager,product.category stock_manager,product.model_product_category,stock.group_stock_manager,1,1,1,1 -access_product_template_stock_manager,product.template stock_manager,product.model_product_template,stock.group_stock_manager,1,1,1,1 -access_product_product_stock_manager,product.product stock_manager,product.model_product_product,stock.group_stock_manager,1,1,1,1 -access_product_packaging_stock_manager,product.packaging stock_manager,product.model_product_packaging,stock.group_stock_manager,1,1,1,1 -access_product_supplierinfo_stock_manager,product.supplierinfo stock_manager,product.model_product_supplierinfo,stock.group_stock_manager,1,1,1,1 -access_pricelist_partnerinfo_stock_manager,pricelist.partnerinfo stock_manager,product.model_pricelist_partnerinfo,stock.group_stock_manager,1,1,1,1 -access_product_price_type_stock_manager,product.price.type stock_manager,product.model_product_price_type,stock.group_stock_manager,1,1,1,1 -access_product_pricelist_type_stock_manager,product.pricelist.type stock_manager,product.model_product_pricelist_type,stock.group_stock_manager,1,1,1,1 -access_product_pricelist_stock_manager,product.pricelist stock_manager,product.model_product_pricelist,stock.group_stock_manager,1,1,1,1 -access_ir_property_group_stock_manager,ir_property group_stock_manager,base.model_ir_property,stock.group_stock_manager,1,1,1,1 -access_product_group_res_partner_stock_manager,res_partner group_stock_manager,base.model_res_partner,stock.group_stock_manager,1,1,1,0 -access_product_pricelist_version_stock_manager,product.pricelist.version stock_manager,product.model_product_pricelist_version,stock.group_stock_manager,1,1,1,1 -access_product_pricelist_item_stock_manager,product.pricelist.item stock_manager,product.model_product_pricelist_item,stock.group_stock_manager,1,1,1,1 -access_account_account_stock_manager,account.account stock manager,account.model_account_account,stock.group_stock_manager,1,0,0,0 -access_board_stock_user,board.board user,board.model_board_board,stock.group_stock_user,1,1,0,0 +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_stock_incoterms_all,stock.incoterms all,model_stock_incoterms,,1,0,0,0 +access_stock_incoterms_manager,stock.incoterms manager,model_stock_incoterms,stock.group_stock_manager,1,1,1,1 +access_stock_warehouse_manager,stock.warehouse.manager,model_stock_warehouse,stock.group_stock_manager,1,1,1,1 +access_stock_warehouse_user,stock.warehouse.user,model_stock_warehouse,base.group_user,1,0,0,0 +access_stock_location__partner_manager,stock.location.partner.manager,model_stock_location,base.group_partner_manager,1,1,1,1 +access_stock_location_manager,stock.location.manager,model_stock_location,stock.group_stock_manager,1,1,1,1 +access_stock_location_user,stock.location.user,model_stock_location,base.group_user,1,0,0,0 +access_stock_journal_user,stock.journal.user,model_stock_journal,base.group_user,1,0,0,0 +access_stock_journal_manager,stock.journal.manager,model_stock_journal,stock.group_stock_manager,1,1,1,1 +access_stock_tracking_user,stock.tracking user,model_stock_tracking,stock.group_stock_user,1,1,1,1 +access_stock_tracking_manager,stock.tracking manager,model_stock_tracking,stock.group_stock_manager,1,0,0,0 +access_stock_tracking_sales_user,stock.tracking sales.user,model_stock_tracking,base.group_sale_salesman,1,1,1,0 +access_stock_picking_user,stock.picking user,model_stock_picking,stock.group_stock_user,1,1,1,1 +access_stock_picking_in_user,stock.picking.in,model_stock_picking_in,stock.group_stock_user,1,1,1,1 +access_stock_picking_out_user,stock.picking.out,model_stock_picking_out,stock.group_stock_user,1,1,1,1 +access_stock_picking_manager,stock.picking manager,model_stock_picking,stock.group_stock_manager,1,1,0,0 +access_stock_picking_in_manager,stock.picking.in manager,model_stock_picking_in,stock.group_stock_manager,1,0,0,0 +access_stock_picking_out_manager,stock.picking.out manager,model_stock_picking_out,stock.group_stock_manager,1,0,0,0 +access_stock_production_lot_manager,stock.production.lot manager,model_stock_production_lot,stock.group_stock_manager,1,0,0,0 +access_stock_production_lot_user,stock.production.lot user,model_stock_production_lot,stock.group_stock_user,1,1,1,1 +access_stock_production_lot_revision,stock.production.lot.revision,model_stock_production_lot_revision,stock.group_stock_user,1,1,1,1 +access_stock_move_manager,stock.move manager,model_stock_move,stock.group_stock_manager,1,1,1,1 +access_stock_move_user,stock.move user,model_stock_move,stock.group_stock_user,1,1,1,0 +access_stock_inventory_user,stock.inventory user,model_stock_inventory,stock.group_stock_user,1,1,1,0 +access_stock_inventory_manager,stock.inventory manager,model_stock_inventory,stock.group_stock_manager,1,1,1,1 +access_stock_inventory_line_user,stock.inventory.line user,model_stock_inventory_line,stock.group_stock_user,1,1,1,0 +access_stock_inventory_line_manager,stock.inventory.line manager,model_stock_inventory_line,stock.group_stock_manager,1,1,1,1 +access_stock_report_prodlots,stock.report.prodlots,model_stock_report_prodlots,stock.group_stock_manager,1,0,0,0 +access_stock_location_sale_manager,stock.location sale manager,model_stock_location,base.group_sale_manager,1,0,0,0 +access_stock_location_stock_manager,stock.location stock manager,model_stock_location,stock.group_stock_manager,1,0,0,0 +access_stock_lines_date_user,report.stock.lines.date user,model_report_stock_lines_date,stock.group_stock_user,1,0,0,0 +access_stock_lines_date_manager,report.stock.lines.date manager,model_report_stock_lines_date,stock.group_stock_manager,1,1,1,1 +access_stock_report_tracklots,stock.report.tracklots,model_stock_report_tracklots,stock.group_stock_user,1,1,1,1 +access_report_stock_move_user,report.stock.move user,model_report_stock_move,stock.group_stock_user,1,0,0,0 +access_report_stock_move_manager,report.stock.move manager,model_report_stock_move,stock.group_stock_manager,1,1,1,1 +access_report_stock_inventory_user,report.stock.inventory user,model_report_stock_inventory,stock.group_stock_user,1,1,1,1 +access_product_product_stock_user,product_product_stock_user,product.model_product_product,stock.group_stock_user,1,1,0,0 +access_product_template_stock_user,product.template stock user,product.model_product_template,stock.group_stock_user,1,1,0,0 +access_account_invoice_user,account.invoice stock user,account.model_account_invoice,stock.group_stock_user,1,1,1,0 +access_account_invoice_line_user,account.invoice.line stock user,account.model_account_invoice_line,stock.group_stock_user,1,1,1,0 +access_account_invoice_tax_user,account.invoice.tax stock user,account.model_account_invoice_tax,stock.group_stock_user,1,1,1,0 +access_account_journal_user,account.journal stock user,account.model_account_journal,stock.group_stock_user,1,0,0,0 +access_account_fiscalyear,account.fiscalyear stock user,account.model_account_fiscalyear,stock.group_stock_user,1,0,0,0 +access_product_pricelist_item_sale_manager,product.pricelist.item salemanager,product.model_product_pricelist_item,base.group_sale_manager,1,1,1,1 +access_product_uom_categ_stock_manager,product.uom.categ stock_manager,product.model_product_uom_categ,stock.group_stock_manager,1,1,1,1 +access_product_uom_stock_manager,product.uom stock_manager,product.model_product_uom,stock.group_stock_manager,1,1,1,1 +access_product_ul_stock_manager,product.ul stock_manager,product.model_product_ul,stock.group_stock_manager,1,1,1,1 +access_product_category_stock_manager,product.category stock_manager,product.model_product_category,stock.group_stock_manager,1,1,1,1 +access_product_template_stock_manager,product.template stock_manager,product.model_product_template,stock.group_stock_manager,1,1,1,1 +access_product_product_stock_manager,product.product stock_manager,product.model_product_product,stock.group_stock_manager,1,1,1,1 +access_product_packaging_stock_manager,product.packaging stock_manager,product.model_product_packaging,stock.group_stock_manager,1,1,1,1 +access_product_supplierinfo_stock_manager,product.supplierinfo stock_manager,product.model_product_supplierinfo,stock.group_stock_manager,1,1,1,1 +access_pricelist_partnerinfo_stock_manager,pricelist.partnerinfo stock_manager,product.model_pricelist_partnerinfo,stock.group_stock_manager,1,1,1,1 +access_product_price_type_stock_manager,product.price.type stock_manager,product.model_product_price_type,stock.group_stock_manager,1,1,1,1 +access_product_pricelist_type_stock_manager,product.pricelist.type stock_manager,product.model_product_pricelist_type,stock.group_stock_manager,1,1,1,1 +access_product_pricelist_stock_manager,product.pricelist stock_manager,product.model_product_pricelist,stock.group_stock_manager,1,1,1,1 +access_ir_property_group_stock_manager,ir_property group_stock_manager,base.model_ir_property,stock.group_stock_manager,1,1,1,1 +access_product_group_res_partner_stock_manager,res_partner group_stock_manager,base.model_res_partner,stock.group_stock_manager,1,1,1,0 +access_product_pricelist_version_stock_manager,product.pricelist.version stock_manager,product.model_product_pricelist_version,stock.group_stock_manager,1,1,1,1 +access_product_pricelist_item_stock_manager,product.pricelist.item stock_manager,product.model_product_pricelist_item,stock.group_stock_manager,1,1,1,1 +access_account_account_stock_manager,account.account stock manager,account.model_account_account,stock.group_stock_manager,1,0,0,0 +access_board_stock_user,board.board user,board.model_board_board,stock.group_stock_user,1,1,0,0 +access_stock_move_matching_manager,stock.move.matching manager,model_stock_move_matching,stock.group_stock_manager,1,1,1,1 +access_stock_move_matching_user,stock.move.matching user,model_stock_move_matching,stock.group_stock_user,1,1,1,0 diff --git a/addons/stock/security/stock_security.xml b/addons/stock/security/stock_security.xml index 10ae6a16d59..fd5a607e98e 100644 --- a/addons/stock/security/stock_security.xml +++ b/addons/stock/security/stock_security.xml @@ -80,5 +80,11 @@ ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + Stock move matching + + + [('1','=','1')] + diff --git a/addons/stock/stock.py b/addons/stock/stock.py index cffc78beb11..c63f6dc2ddc 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1204,7 +1204,6 @@ class stock_picking(osv.osv): - # FIXME: needs refactoring, this code is partially duplicated in stock_move.do_partial()! def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking and moves done. @param partial_datas : Dictionary containing details of partial picking @@ -1229,7 +1228,7 @@ class stock_picking(osv.osv): move_product_qty, prodlot_ids, product_avail, partial_qty, product_uoms = {}, {}, {}, {}, {} move_ids = [x.id for x in pick.move_lines] - move_obj.price_computation(cr, uid, move_ids, partial_datas, context=context) + #move_obj.price_computation(cr, uid, move_ids, partial_datas, context=context) for move in pick.move_lines: if move.state in ('done', 'cancel'): @@ -1631,11 +1630,11 @@ class stock_move(osv.osv): return True #TODO: change demo data for this to be possible def _check_company_location(self, cr, uid, ids, context=None): -# for record in self.browse(cr, uid, ids, context=context): -# if record.location_id.company_id and (record.company_id.id != record.location_id.company_id.id): -# raise osv.except_osv(_('Error'), _('The company of the source location %s and the company of the stock move should be the same') % record.location_id.name) -# if record.location_dest_id.company_id and (record.company_id.id != record.location_dest_id.company_id.id): -# raise osv.except_osv(_('Error'), _('The company of the destination location %s and the company of the stock move should be the same') % record.location_dest_id.name) + for record in self.browse(cr, uid, ids, context=context): + if record.location_id.company_id and (record.company_id.id != record.location_id.company_id.id): + raise osv.except_osv(_('Error'), _('The company of the source location %s and the company of the stock move should be the same') % record.location_id.name) + if record.location_dest_id.company_id and (record.company_id.id != record.location_dest_id.company_id.id): + raise osv.except_osv(_('Error'), _('The company of the destination location %s and the company of the stock move should be the same') % record.location_dest_id.name) return True _constraints = [ @@ -2361,6 +2360,8 @@ class stock_move(osv.osv): self.action_confirm(cr, uid, todo, context=context) todo = [] + #Do price calculation on moves + self.price_calculation(cr, uid, ids, context=context) for move in self.browse(cr, uid, ids, context=context): if move.state in ['done','cancel']: continue @@ -2658,7 +2659,84 @@ class stock_move(osv.osv): return res - + def price_calculation(self, cr, uid, ids, context=None): + ''' + This method puts the right price on the stock move + ''' + product_obj = self.pool.get('product.product') + currency_obj = self.pool.get('res.currency') + matching_obj = self.pool.get('stock.move.matching') + uom_obj = self.pool.get('product.uom') + + product_avail = {} + for move in self.browse(cr, uid, ids, context=context): + # Initialize variables + product_qty = move.product_qty + product_uom = move.product_uom.id + company_id = move.company_id.id + ctx = context.copy() + user = self.pool.get('res.users').browse(cr, uid, uid, context=context) + if company_id != user.company_id.id: + ctx['force_company'] = move.company_id.id + product = product_obj.browse(cr, uid, move.product_id.id, context=ctx) + cost_method = product.cost_method + product_uom_qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id) + + # Check if out -> do stock move matchings and if fifo/lifo -> update price + if move.location_id.usage == 'internal' and move.location_dest_id.usage != 'internal': + + fifo = (cost_method != 'lifo') + tuples = product_obj.get_stock_matchings_fifolifo(cr, uid, [product.id], product_qty, fifo, + product_uom, move.company_id.currency_id.id, context=ctx) + price_amount = 0.0 + amount = 0.0 + #Write stock matchings + for match in tuples: + matchvals = {'move_in_id': match[0], 'qty': match[1], + 'move_out_id': move.id, 'price_unit_out': match[2]} + match_id = matching_obj.create(cr, uid, matchvals, context=context) + move_in = self.browse(cr, uid, match[0], context=context) + #Reduce remaining quantity + self.write(cr, uid, match[0], { 'qty_remaining': move_in.qty_remaining - match[3]}, context=context) + price_amount += match[1] * match[2] + amount += match[1] + #Write price on out move + if product.qty_available >= product_uom_qty and product.cost_method in ['fifo', 'lifo']: + self.write(cr, uid, move.id, {'price_unit': price_amount / amount}, context=context) + product_obj.write(cr, uid, product.id, {'standard_price': price_amount / product_uom_qty}, context=ctx) + else: + new_price = uom_obj._compute_price(cr, uid, product.uom_id.id, product.standard_price, + product_uom) + self.write(cr, uid, move.id, {'price_unit': new_price}, context=ctx) + + + if not product.id in product_avail: + product_avail[product.id] = product.qty_available + #Check if in => if price 0.0, take standard price / Update price when average price and price on move != standard price + if move.location_id.usage != 'internal' and move.location_dest_id.usage == 'internal': + if move.price_unit == 0.0: + new_price = uom_obj._compute_price(cr, uid, product.uom_id.id, product.standard_price, product_uom) + self.write(cr, uid, move.id, {'price_unit': new_price}, context=ctx) + elif product.cost_method == 'average': + if product_avail[product.id] >= 0.0: + amount_unit = product.standard_price + move_product_price = uom_obj._compute_price(cr, uid, product_uom, move.price_unit, product.uom_id.id) + new_std_price = ((amount_unit * product_avail[product.id])\ + + (move_product_price * product_uom_qty))/(product_avail[product.id] + product_uom_qty) + product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price}, context=ctx) + product_avail[product.id] += product.qty_available + + #This could be made optional + if move.location_id.usage == 'internal' and move.location_dest_id.usage != 'internal' and cost_method == 'average' and move.move_returned_from: + move_orig = move.move_returned_from + new_price = uom_obj._compute_price(cr, uid, move_orig.product_uom, move_orig.price_unit, product.uom_id.id) + if (product_avail[product.id]- product_uom_qty) >= 0.0: + amount_unit = product.standard_price + new_std_price = ((amount_unit * product_avail[product.id])\ + - (new_price * product_uom_qty))/(product_avail[product.id] - product_uom_qty) + self.write(cr, uid, [move.id],{'price_unit': move_orig.price_unit,}) + product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price}, context=ctx) + product_avail[product.id] -= product_uom_qty def price_computation(self, cr, uid, ids, partial_datas, context=None): ''' @@ -2765,7 +2843,7 @@ class stock_move(osv.osv): #Let us do the price calculation move_ids = [x.id for x in self.browse(cr, uid, ids, context=context)] - self.price_computation(cr, uid, move_ids, partial_datas, context=context) + #self.price_computation(cr, uid, move_ids, partial_datas, context=context) for move in self.browse(cr, uid, ids, context=context): if move.state in ('done', 'cancel'): diff --git a/addons/stock_fifo_lifo/stock_fifo_lifo.py b/addons/stock/stock_fifo_lifo.py similarity index 93% rename from addons/stock_fifo_lifo/stock_fifo_lifo.py rename to addons/stock/stock_fifo_lifo.py index 2e7b76da7c1..33882d9441c 100644 --- a/addons/stock_fifo_lifo/stock_fifo_lifo.py +++ b/addons/stock/stock_fifo_lifo.py @@ -23,20 +23,10 @@ from openerp import tools from openerp.osv import osv, fields -#@TODO Should not this be product template? #TODO: remove this module and put everything in existing core modules (purchase, stock, product...) class product_product (osv.osv): _name = "product.product" _inherit = "product.product" -# _columns = { -# 'cost_method': fields.property('', type='selection', view_load=True, selection = [('standard','Standard Price'), ('average','Average Price'), -# ('fifo', 'FIFO price'), ('lifo', 'LIFO price')], -# help="""Standard Price: The cost price is manually updated at the end of a specific period (usually every year). -# Average Price: The cost price is recomputed at each incoming shipment. -# FIFO: When cost is calculated the FIFO way. -# LIFO: When cost is calculated the LIFO way. """, -# string="Costing Method"), -# } def get_stock_matchings_fifolifo(self, cr, uid, ids, qty, fifo, product_uom_id = False, currency_id = False, context=None): @@ -120,6 +110,8 @@ class stock_move(osv.osv): return res + + #Overwrites method for FIFO computation def price_computation(self, cr, uid, ids, partial_datas, context=None): super(stock_move, self).price_computation(cr, uid, ids, partial_datas, context=context) @@ -198,8 +190,7 @@ class stock_move(osv.osv): new_price = product_price else: if product_uom != uom_id: - new_price = uom_obj._compute_price(cr, uid, uom_id, new_price, - product_uom) + new_price = uom_obj._compute_price(cr, uid, uom_id, new_price, product_uom) else: new_price = product.standard_price self.write(cr, uid, [move.id], diff --git a/addons/stock/wizard/stock_partial_picking.py b/addons/stock/wizard/stock_partial_picking.py index b95c3760030..cbb3e7b5981 100644 --- a/addons/stock/wizard/stock_partial_picking.py +++ b/addons/stock/wizard/stock_partial_picking.py @@ -209,8 +209,16 @@ class stock_partial_picking(osv.osv_memory): 'prodlot_id': wizard_line.prodlot_id.id, } if (picking_type == 'in') and (wizard_line.product_id.cost_method != 'standard'): - partial_data['move%s' % (wizard_line.move_id.id)].update(product_price=wizard_line.cost, - product_currency=wizard_line.currency.id) + #TODO Maybe better ways to get company or main currency + #TODO Should not this currency be calculated at the date of the purchase order? (not the case now?) + if wizard_line.location_id.company_id: + company = wizard_line.location_id.company_id + else: + company = wizard_line.location_dest_id.company_id + currency_obj = self.pool.get("res.currency") + new_price = currency_obj.compute(cr, uid, wizard_line.currency.id, company.currency_id.id, + wizard_line.cost, round=False) + partial_data['move%s' % (wizard_line.move_id.id)].update(product_price=wizard_line.cost,) stock_picking.do_partial(cr, uid, [partial.picking_id.id], partial_data, context=context) return {'type': 'ir.actions.act_window_close'} diff --git a/addons/stock_fifo_lifo/__init__.py b/addons/stock_fifo_lifo/__init__.py deleted file mode 100644 index ba8157ec7af..00000000000 --- a/addons/stock_fifo_lifo/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2013 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 . -# -############################################################################## - -from stock_fifo_lifo import * - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock_fifo_lifo/__openerp__.py b/addons/stock_fifo_lifo/__openerp__.py deleted file mode 100644 index 91a4571b7f2..00000000000 --- a/addons/stock_fifo_lifo/__openerp__.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- 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 . -# -############################################################################## - -{ - 'name': 'FIFO/LIFO stock valuation', - 'version': '0.1', - 'author': 'OpenERP SA', - 'summary': 'Valorize your stock FIFO/LIFO', - 'description' : """ -Manage FIFO/LIFO stock valuation -================================ - -This gives reports which value the stock in a FIFO/LIFO way. It adds a table to match the outs with the ins. - """, - 'website': 'http://www.openerp.com', - 'images': [], - 'depends': ['purchase'], - 'category': 'Warehouse Management', - 'sequence': 16, - 'demo': [ - ], - 'data': ['security/ir.model.access.csv' - ], - 'test': ['test/fifolifo_price.yml', - 'test/lifo_price.yml' - ], - 'installable': True, - 'application': True, - 'auto_install': False, - 'css': [], -} - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock_fifo_lifo/security/ir.model.access.csv b/addons/stock_fifo_lifo/security/ir.model.access.csv deleted file mode 100644 index 75808c05f40..00000000000 --- a/addons/stock_fifo_lifo/security/ir.model.access.csv +++ /dev/null @@ -1,3 +0,0 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_stock_move_matching_manager,stock.move.matching manager,model_stock_move_matching,stock.group_stock_manager,1,1,1,1 -access_stock_move_matching_user,stock.move.matching user,model_stock_move_matching,stock.group_stock_user,1,1,1,0 diff --git a/addons/stock_fifo_lifo/security/stock_matching_security.xml b/addons/stock_fifo_lifo/security/stock_matching_security.xml deleted file mode 100644 index aedc465c7a0..00000000000 --- a/addons/stock_fifo_lifo/security/stock_matching_security.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - stock_move matching - - - [('1','=','1')] - - - -