diff --git a/addons/purchase_price_diff/__init__.py b/addons/purchase_price_diff/__init__.py deleted file mode 100644 index dc5e6b693d1..00000000000 --- a/addons/purchase_price_diff/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from . import models diff --git a/addons/purchase_price_diff/__manifest__.py b/addons/purchase_price_diff/__manifest__.py deleted file mode 100644 index 858277fc060..00000000000 --- a/addons/purchase_price_diff/__manifest__.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -{ - 'name': 'WMS Accounting', - 'version': '1.1', - 'summary': 'Inventory, Logistic, Valuation, Accounting', - 'description': """ -WMS Accounting module -====================== -This module adds the price difference account. Used in standard perpetual valuation. - """, - 'depends': ['purchase_stock'], - 'data': [ - 'views/product_views.xml', - ], - 'category': 'Hidden', - 'sequence': 16, - 'auto_install': True, - 'license': 'LGPL-3', -} diff --git a/addons/purchase_price_diff/models/__init__.py b/addons/purchase_price_diff/models/__init__.py deleted file mode 100644 index 715bc52324a..00000000000 --- a/addons/purchase_price_diff/models/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from . import account_move_line -from . import product diff --git a/addons/purchase_price_diff/models/account_move_line.py b/addons/purchase_price_diff/models/account_move_line.py deleted file mode 100644 index 36ccf7a8004..00000000000 --- a/addons/purchase_price_diff/models/account_move_line.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- - -from odoo import models - -class AccountMoveLine(models.Model): - _inherit = 'account.move.line' - - def _get_price_diff_account(self): - self.ensure_one() - if self.product_id.cost_method == 'standard': - debit_pdiff_account = self.product_id.property_account_creditor_price_difference \ - or self.product_id.categ_id.property_account_creditor_price_difference_categ - debit_pdiff_account = self.move_id.fiscal_position_id.map_account(debit_pdiff_account) - return debit_pdiff_account - return super()._get_price_diff_account() diff --git a/addons/purchase_price_diff/models/product.py b/addons/purchase_price_diff/models/product.py deleted file mode 100644 index 2f47646862d..00000000000 --- a/addons/purchase_price_diff/models/product.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import fields, models - - -class ProductCategory(models.Model): - _inherit = "product.category" - - property_account_creditor_price_difference_categ = fields.Many2one( - 'account.account', string="Price Difference Account", - company_dependent=True, - help="This account will be used to value price difference between purchase price and accounting cost.") - - -class ProductTemplate(models.Model): - _name = 'product.template' - _inherit = 'product.template' - - property_account_creditor_price_difference = fields.Many2one( - 'account.account', string="Price Difference Account", company_dependent=True, - help="This account is used in automated inventory valuation to "\ - "record the price difference between a purchase order and its related vendor bill when validating this vendor bill.") diff --git a/addons/purchase_stock/__manifest__.py b/addons/purchase_stock/__manifest__.py index 8578fe0ed71..47ce2b411a4 100644 --- a/addons/purchase_stock/__manifest__.py +++ b/addons/purchase_stock/__manifest__.py @@ -19,6 +19,7 @@ 'views/res_config_settings_views.xml', 'views/res_partner_views.xml', 'views/stock_lot_views.xml', + 'views/product_views.xml', 'report/purchase_report_views.xml', 'report/purchase_report_templates.xml', 'report/report_stock_rule.xml', diff --git a/addons/purchase_stock/models/account_invoice.py b/addons/purchase_stock/models/account_invoice.py index 9a5adae6690..979461cec1f 100644 --- a/addons/purchase_stock/models/account_invoice.py +++ b/addons/purchase_stock/models/account_invoice.py @@ -42,8 +42,14 @@ class AccountMove(models.Model): continue # Retrieve accounts needed to generate the price difference. - debit_expense_account = line._get_price_diff_account() - if not debit_expense_account: + debit_pdiff_account = False + if line.product_id.cost_method == 'standard': + debit_pdiff_account = line.product_id.property_account_creditor_price_difference \ + or line.product_id.categ_id.property_account_creditor_price_difference_categ + debit_pdiff_account = move.fiscal_position_id.map_account(debit_pdiff_account) + else: + debit_pdiff_account = line.product_id.product_tmpl_id.get_product_accounts(fiscal_pos=move.fiscal_position_id)['expense'] + if not debit_pdiff_account: continue # Retrieve stock valuation moves. valuation_stock_moves = self.env['stock.move'].search([ @@ -74,7 +80,6 @@ class AccountMove(models.Model): move.company_id, valuation_date, round=False ) - price_unit = line._get_gross_unit_price() price_unit_val_dif = price_unit - valuation_price_unit @@ -110,7 +115,7 @@ class AccountMove(models.Model): line.company_currency_id, line.company_id, fields.Date.today(), ), - 'account_id': debit_expense_account.id, + 'account_id': debit_pdiff_account.id, 'analytic_distribution': line.analytic_distribution, 'display_type': 'cogs', } diff --git a/addons/purchase_stock/models/account_move_line.py b/addons/purchase_stock/models/account_move_line.py index c23de0faf4b..96064adb5bc 100644 --- a/addons/purchase_stock/models/account_move_line.py +++ b/addons/purchase_stock/models/account_move_line.py @@ -25,10 +25,3 @@ class AccountMoveLine(models.Model): total_out_and_not_invoiced_qty = max(0, out_qty - invoiced_qty) out_and_not_invoiced_qty = min(aml_qty, total_out_and_not_invoiced_qty) return self.product_id.uom_id._compute_quantity(out_and_not_invoiced_qty, self.product_uom_id) - - def _get_price_diff_account(self): - self.ensure_one() - if self.product_id.cost_method == 'standard': - return False - accounts = self.product_id.product_tmpl_id.get_product_accounts(fiscal_pos=self.move_id.fiscal_position_id) - return accounts['expense'] diff --git a/addons/purchase_stock/models/product.py b/addons/purchase_stock/models/product.py index f93667c834d..bb54de04479 100644 --- a/addons/purchase_stock/models/product.py +++ b/addons/purchase_stock/models/product.py @@ -5,10 +5,24 @@ from odoo import api, fields, models from odoo.osv import expression +class ProductCategory(models.Model): + _inherit = "product.category" + + property_account_creditor_price_difference_categ = fields.Many2one( + 'account.account', string="Price Difference Account", + company_dependent=True, + help="This account will be used to value price difference between purchase price and accounting cost.") + + class ProductTemplate(models.Model): _name = 'product.template' _inherit = 'product.template' + property_account_creditor_price_difference = fields.Many2one( + 'account.account', string="Price Difference Account", company_dependent=True, + help="This account is used in automated inventory valuation to "\ + "record the price difference between a purchase order and its related vendor bill when validating this vendor bill.") + @api.model def _get_buy_route(self): buy_route = self.env.ref('purchase_stock.route_warehouse0_buy', raise_if_not_found=False) diff --git a/addons/purchase_price_diff/views/product_views.xml b/addons/purchase_stock/views/product_views.xml similarity index 92% rename from addons/purchase_price_diff/views/product_views.xml rename to addons/purchase_stock/views/product_views.xml index da6712009c9..89d86841fc7 100644 --- a/addons/purchase_price_diff/views/product_views.xml +++ b/addons/purchase_stock/views/product_views.xml @@ -1,7 +1,7 @@ - product.category.property.form.inherit.stock + product.category.property.form.inherit.purchase.stock product.category @@ -14,7 +14,7 @@ - product.normal.form.inherit.stock + product.normal.form.inherit.purchase.stock product.template @@ -23,4 +23,4 @@ - \ No newline at end of file +