From 038fd04ea5bcd20b8aa5e57b5608caa071aec34b Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 11 Jul 2013 15:05:28 +0200 Subject: [PATCH] [WIP] split stock module in stock and stock_account that installs itself only if account+stock are installed bzr revid: qdp-launchpad@openerp.com-20130711130528-c9jjiduqriakj9iv --- addons/stock/__openerp__.py | 19 +- addons/stock/partner.py | 1 + addons/stock/product.py | 193 ------ addons/stock/product_view.xml | 66 +- addons/stock/res_config.py | 2 +- addons/stock/res_config_view.xml | 4 +- addons/stock/security/ir.model.access.csv | 6 - addons/stock/security/stock_security.xml | 5 - addons/stock/stock.py | 576 ++-------------- addons/stock/stock_data.xml | 12 - addons/stock/stock_demo.xml | 7 - addons/stock/stock_demo.yml | 2 - addons/stock/stock_view.xml | 20 +- addons/stock/test/shipment.yml | 17 - addons/stock/wizard/__init__.py | 2 - addons/stock_account/__init__.py | 26 + addons/stock_account/__openerp__.py | 94 +++ addons/stock_account/product.py | 231 +++++++ .../{stock => stock_account}/product_data.xml | 0 addons/stock_account/product_view.xml | 91 +++ .../security/ir.model.access.csv | 7 + addons/stock_account/stock_account.py | 634 ++++++++++++++++++ addons/stock_account/stock_account_data.xml | 19 + addons/stock_account/stock_account_demo.xml | 14 + addons/stock_account/stock_account_view.xml | 90 +++ .../wizard/stock_change_standard_price.py | 0 .../stock_change_standard_price_view.xml | 0 .../wizard/stock_invoice_onshipping.py | 0 .../wizard/stock_invoice_onshipping_view.xml | 0 29 files changed, 1262 insertions(+), 876 deletions(-) create mode 100644 addons/stock_account/__init__.py create mode 100644 addons/stock_account/__openerp__.py create mode 100644 addons/stock_account/product.py rename addons/{stock => stock_account}/product_data.xml (100%) create mode 100644 addons/stock_account/product_view.xml create mode 100644 addons/stock_account/security/ir.model.access.csv create mode 100644 addons/stock_account/stock_account.py create mode 100644 addons/stock_account/stock_account_data.xml create mode 100644 addons/stock_account/stock_account_demo.xml create mode 100644 addons/stock_account/stock_account_view.xml rename addons/{stock => stock_account}/wizard/stock_change_standard_price.py (100%) rename addons/{stock => stock_account}/wizard/stock_change_standard_price_view.xml (100%) rename addons/{stock => stock_account}/wizard/stock_invoice_onshipping.py (100%) rename addons/{stock => stock_account}/wizard/stock_invoice_onshipping_view.xml (100%) diff --git a/addons/stock/__openerp__.py b/addons/stock/__openerp__.py index fbd5b977ea2..14335a7fdbd 100644 --- a/addons/stock/__openerp__.py +++ b/addons/stock/__openerp__.py @@ -24,12 +24,12 @@ 'version': '1.1', 'author': 'OpenERP SA', 'summary': 'Inventory, Logistic, Storage', - 'description' : """ + 'description': """ Manage multi-warehouses, multi- and structured stock locations ============================================================== -The warehouse and inventory management is based on a hierarchical location structure, from warehouses to storage bins. -The double entry inventory system allows you to manage customers, suppliers as well as manufacturing inventories. +The warehouse and inventory management is based on a hierarchical location structure, from warehouses to storage bins. +The double entry inventory system allows you to manage customers, suppliers as well as manufacturing inventories. OpenERP has the capacity to manage lots and serial numbers ensuring compliance with the traceability requirements imposed by the majority of industries. @@ -53,8 +53,8 @@ Dashboard / Reports for Warehouse Management will include: * Moves Analysis """, 'website': 'http://www.openerp.com', - 'images': ['images/stock_forecast_report.png', 'images/delivery_orders.jpeg', 'images/inventory_analysis.jpeg','images/location.jpeg','images/moves_analysis.jpeg','images/physical_inventories.jpeg','images/warehouse_dashboard.jpeg'], - 'depends': ['product', 'account','procurement'], + 'images': ['images/stock_forecast_report.png', 'images/delivery_orders.jpeg', 'images/inventory_analysis.jpeg', 'images/location.jpeg', 'images/moves_analysis.jpeg', 'images/physical_inventories.jpeg', 'images/warehouse_dashboard.jpeg'], + 'depends': ['product', 'procurement', 'board'], 'category': 'Warehouse Management', 'sequence': 16, 'demo': [ @@ -72,12 +72,10 @@ Dashboard / Reports for Warehouse Management will include: 'wizard/stock_partial_picking_view.xml', 'wizard/stock_partial_move_view.xml', 'wizard/stock_fill_inventory_view.xml', - 'wizard/stock_invoice_onshipping_view.xml', 'wizard/stock_inventory_merge_view.xml', 'wizard/stock_location_product_view.xml', 'wizard/stock_splitinto_view.xml', 'wizard/stock_inventory_line_split_view.xml', - 'wizard/stock_change_standard_price_view.xml', 'wizard/stock_return_picking_view.xml', 'wizard/make_procurement_view.xml', 'wizard/mrp_procurement_view.xml', @@ -87,7 +85,6 @@ Dashboard / Reports for Warehouse Management will include: 'stock_report.xml', 'stock_view.xml', 'stock_sequence.xml', - 'product_data.xml', 'product_view.xml', 'partner_view.xml', 'report/report_stock_move_view.xml', @@ -103,15 +100,15 @@ Dashboard / Reports for Warehouse Management will include: 'installable': True, 'application': True, 'auto_install': False, - 'css': [ + 'css': [ 'static/src/css/picking.css', - 'static/src/css/stock.css', + 'static/src/css/stock.css', ], 'js': [ 'static/src/js/widgets.js', 'static/src/js/main.js', ], - 'qweb':['static/src/xml/picking.xml'], + 'qweb': ['static/src/xml/picking.xml'], } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/partner.py b/addons/stock/partner.py index 3b193cb447e..0998ddf0b44 100644 --- a/addons/stock/partner.py +++ b/addons/stock/partner.py @@ -36,3 +36,4 @@ class res_partner(osv.osv): help="This stock location will be used, instead of the default one, as the source location for goods you receive from the current partner"), } +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/product.py b/addons/stock/product.py index ed39faf790e..dec76623ce4 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -47,147 +47,6 @@ class product_product(osv.osv): res[product_id]['delivery_count'] = move['product_id_count'] return res - def get_product_accounts(self, cr, uid, product_id, context=None): - """ To get the stock input account, stock output account and stock journal related to product. - @param product_id: product id - @return: dictionary which contains information regarding stock input account, stock output account and stock journal - """ - if context is None: - context = {} - product_obj = self.pool.get('product.product').browse(cr, uid, product_id, context=context) - - stock_input_acc = product_obj.property_stock_account_input and product_obj.property_stock_account_input.id or False - if not stock_input_acc: - stock_input_acc = product_obj.categ_id.property_stock_account_input_categ and product_obj.categ_id.property_stock_account_input_categ.id or False - - stock_output_acc = product_obj.property_stock_account_output and product_obj.property_stock_account_output.id or False - if not stock_output_acc: - stock_output_acc = product_obj.categ_id.property_stock_account_output_categ and product_obj.categ_id.property_stock_account_output_categ.id or False - - journal_id = product_obj.categ_id.property_stock_journal and product_obj.categ_id.property_stock_journal.id or False - account_valuation = product_obj.categ_id.property_stock_valuation_account_id and product_obj.categ_id.property_stock_valuation_account_id.id or False - return { - 'stock_account_input': stock_input_acc, - 'stock_account_output': stock_output_acc, - 'stock_journal': journal_id, - 'property_stock_valuation_account_id': account_valuation - } - - # FP Note:;too complex, not good, should be implemented at quant level TODO - def do_change_standard_price(self, cr, uid, ids, datas, context=None): - """ Changes the Standard Price of Product and creates an account move accordingly. - @param datas : dict. contain default datas like new_price, stock_output_account, stock_input_account, stock_journal - @param context: A standard dictionary - @return: - - """ - location_obj = self.pool.get('stock.location') - move_obj = self.pool.get('account.move') - move_line_obj = self.pool.get('account.move.line') - if context is None: - context = {} - - new_price = datas.get('new_price', 0.0) - stock_output_acc = datas.get('stock_output_account', False) - stock_input_acc = datas.get('stock_input_account', False) - journal_id = datas.get('stock_journal', False) - product_obj=self.browse(cr, uid, ids, context=context)[0] - account_valuation = product_obj.categ_id.property_stock_valuation_account_id - account_valuation_id = account_valuation and account_valuation.id or False - if not account_valuation_id: raise osv.except_osv(_('Error!'), _('Specify valuation Account for Product Category: %s.') % (product_obj.categ_id.name)) - move_ids = [] - loc_ids = location_obj.search(cr, uid,[('usage','=','internal')]) - for rec_id in ids: - for location in location_obj.browse(cr, uid, loc_ids, context=context): - c = context.copy() - c.update({ - 'location': location.id, - 'compute_child': False - }) - - product = self.browse(cr, uid, rec_id, context=c) - qty = product.qty_available - diff = product.standard_price - new_price - if not diff: raise osv.except_osv(_('Error!'), _("No difference between standard price and new price!")) - if qty: - company_id = location.company_id and location.company_id.id or False - if not company_id: raise osv.except_osv(_('Error!'), _('Please specify company in Location.')) - # - # Accounting Entries - # - if not journal_id: - journal_id = product.categ_id.property_stock_journal and product.categ_id.property_stock_journal.id or False - if not journal_id: - raise osv.except_osv(_('Error!'), - _('Please define journal '\ - 'on the product category: "%s" (id: %d).') % \ - (product.categ_id.name, - product.categ_id.id,)) - move_id = move_obj.create(cr, uid, { - 'journal_id': journal_id, - 'company_id': company_id - }) - - move_ids.append(move_id) - - - if diff > 0: - if not stock_input_acc: - stock_input_acc = product.\ - property_stock_account_input.id - if not stock_input_acc: - stock_input_acc = product.categ_id.\ - property_stock_account_input_categ.id - if not stock_input_acc: - raise osv.except_osv(_('Error!'), - _('Please define stock input account ' \ - 'for this product: "%s" (id: %d).') % \ - (product.name, - product.id,)) - amount_diff = qty * diff - move_line_obj.create(cr, uid, { - 'name': product.name, - 'account_id': stock_input_acc, - 'debit': amount_diff, - 'move_id': move_id, - }) - move_line_obj.create(cr, uid, { - 'name': product.categ_id.name, - 'account_id': account_valuation_id, - 'credit': amount_diff, - 'move_id': move_id - }) - elif diff < 0: - if not stock_output_acc: - stock_output_acc = product.\ - property_stock_account_output.id - if not stock_output_acc: - stock_output_acc = product.categ_id.\ - property_stock_account_output_categ.id - if not stock_output_acc: - raise osv.except_osv(_('Error!'), - _('Please define stock output account ' \ - 'for this product: "%s" (id: %d).') % \ - (product.name, - product.id,)) - amount_diff = qty * -diff - move_line_obj.create(cr, uid, { - 'name': product.name, - 'account_id': stock_output_acc, - 'credit': amount_diff, - 'move_id': move_id - }) - move_line_obj.create(cr, uid, { - 'name': product.categ_id.name, - 'account_id': account_valuation_id, - 'debit': amount_diff, - 'move_id': move_id - }) - - self.write(cr, uid, rec_id, {'standard_price': new_price}) - - return move_ids - def view_header_get(self, cr, user, view_id, view_type, context=None): if context is None: context = {} @@ -343,15 +202,6 @@ class product_product(osv.osv): 'track_outgoing': fields.boolean('Track Outgoing Lots', help="Forces to specify a Serial Number for all moves containing this product and going to a Customer Location"), 'location_id': fields.dummy(string='Location', relation='stock.location', type='many2one'), 'warehouse_id': fields.dummy(string='Warehouse', relation='stock.warehouse', type='many2one'), - 'valuation':fields.property(type='selection', selection=[('manual_periodic', 'Periodical (manual)'), - ('real_time','Real Time (automated)'),], string = 'Inventory Valuation', - help="If real-time valuation is enabled for a product, the system will automatically write journal entries corresponding to stock moves." \ - "The inventory variation account set on the product category will represent the current inventory value, and the stock input and stock output account will hold the counterpart moves for incoming and outgoing products." - , required=True), - } - - _defaults = { - 'valuation': 'manual_periodic', } def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): @@ -420,18 +270,6 @@ class product_template(osv.osv): string="Inventory Location", domain=[('usage','like','inventory')], help="This stock location will be used, instead of the default one, as the source location for stock moves generated when you do an inventory."), - 'property_stock_account_input': fields.property( - type='many2one', - relation='account.account', - string='Stock Input Account', - help="When doing real-time inventory valuation, counterpart journal items for all incoming stock moves will be posted in this account, unless " - "there is a specific valuation account set on the source location. When not set on the product, the one from the product category is used."), - 'property_stock_account_output': fields.property( - type='many2one', - relation='account.account', - string='Stock Output Account', - help="When doing real-time inventory valuation, counterpart journal items for all outgoing stock moves will be posted in this account, unless " - "there is a specific valuation account set on the destination location. When not set on the product, the one from the product category is used."), 'sale_delay': fields.float('Customer Lead Time', help="The average delay in days between the confirmation of the customer order and the delivery of the finished products. It's the time you promise to your customers."), 'loc_rack': fields.char('Rack', size=16), 'loc_row': fields.char('Row', size=16), @@ -443,35 +281,4 @@ class product_template(osv.osv): } - -class product_category(osv.osv): - _inherit = 'product.category' - _columns = { - 'property_stock_journal': fields.property( - relation='account.journal', - type='many2one', - string='Stock Journal', - help="When doing real-time inventory valuation, this is the Accounting Journal in which entries will be automatically posted when stock moves are processed."), - 'property_stock_account_input_categ': fields.property( - type='many2one', - relation='account.account', - string='Stock Input Account', - help="When doing real-time inventory valuation, counterpart journal items for all incoming stock moves will be posted in this account, unless " - "there is a specific valuation account set on the source location. This is the default value for all products in this category. It " - "can also directly be set on each product"), - 'property_stock_account_output_categ': fields.property( - type='many2one', - relation='account.account', - string='Stock Output Account', - help="When doing real-time inventory valuation, counterpart journal items for all outgoing stock moves will be posted in this account, unless " - "there is a specific valuation account set on the destination location. This is the default value for all products in this category. It " - "can also directly be set on each product"), - 'property_stock_valuation_account_id': fields.property( - type='many2one', - relation='account.account', - string="Stock Valuation Account", - help="When real-time inventory valuation is enabled on a product, this account will hold the current value of the products.",), - } - - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/product_view.xml b/addons/stock/product_view.xml index 40d16f2bc63..ff079b7bd58 100644 --- a/addons/stock/product_view.xml +++ b/addons/stock/product_view.xml @@ -14,24 +14,6 @@ - - product.category.stock.property.form.inherit - product.category - - - - - - - - - - - - - - - product.template.stock.property.form.inherit product.template @@ -48,16 +30,12 @@ - + - - - - @@ -131,48 +109,6 @@ - - product.product.standard.price.form.inherit - product.product - - - - - - - - - product.normal.stock.acc.property.form.inherit - product.product - - 26 - - - - - - - - - - - - - - - - - - Receptions stock.move diff --git a/addons/stock/res_config.py b/addons/stock/res_config.py index d0b0563875c..0f9e1e5943f 100644 --- a/addons/stock/res_config.py +++ b/addons/stock/res_config.py @@ -62,7 +62,7 @@ This installs the module product_expiry."""), 'group_stock_tracking_lot': fields.boolean("Track serial number on logistic units (pallets)", implied_group='stock.group_tracking_lot', help="""When you select a serial number on product moves, you can get the upstream or downstream traceability of that product."""), - 'group_stock_inventory_valuation': fields.boolean("Generate accounting entries per stock movement", + 'module_stock_account': fields.boolean("Generate accounting entries per stock movement", implied_group='stock.group_inventory_valuation', help="""Allows to configure inventory valuations on products and product categories."""), 'group_stock_multiple_locations': fields.boolean("Manage multiple locations and warehouses", diff --git a/addons/stock/res_config_view.xml b/addons/stock/res_config_view.xml index 133e6ffa875..f5015b146b5 100644 --- a/addons/stock/res_config_view.xml +++ b/addons/stock/res_config_view.xml @@ -45,8 +45,8 @@