[FIX] call _get_product_accounts() everywhere
closes odoo/odoo#41632 Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
@@ -52,3 +52,10 @@ class ProductTemplate(models.Model):
|
||||
if not fiscal_pos:
|
||||
fiscal_pos = self.env['account.fiscal.position']
|
||||
return fiscal_pos.map_accounts(accounts)
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = "product.product"
|
||||
|
||||
def _get_product_accounts(self):
|
||||
return self.product_tmpl_id._get_product_accounts()
|
||||
|
||||
@@ -445,7 +445,7 @@ class PosSession(models.Model):
|
||||
('product_id.categ_id.property_valuation', '=', 'real_time')
|
||||
])
|
||||
for move in stock_moves:
|
||||
exp_key = move.product_id.property_account_expense_id or move.product_id.categ_id.property_account_expense_categ_id
|
||||
exp_key = move.product_id._get_product_accounts()['expense']
|
||||
out_key = move.product_id.categ_id.property_stock_account_output_categ_id
|
||||
amount = -sum(move.stock_valuation_layer_ids.mapped('value'))
|
||||
stock_expense[exp_key] = self._update_amounts(stock_expense[exp_key], {'amount': amount}, move.picking_id.date)
|
||||
@@ -467,7 +467,7 @@ class PosSession(models.Model):
|
||||
('product_id.categ_id.property_valuation', '=', 'real_time'),
|
||||
])
|
||||
for move in stock_moves:
|
||||
exp_key = move.product_id.property_account_expense_id or move.product_id.categ_id.property_account_expense_categ_id
|
||||
exp_key = move.product_id._get_product_accounts()['expense']
|
||||
out_key = move.product_id.categ_id.property_stock_account_output_categ_id
|
||||
amount = -sum(move.stock_valuation_layer_ids.mapped('value'))
|
||||
stock_expense[exp_key] = self._update_amounts(stock_expense[exp_key], {'amount': amount}, move.picking_id.date)
|
||||
@@ -600,7 +600,7 @@ class PosSession(models.Model):
|
||||
"""
|
||||
def get_income_account(order_line):
|
||||
product = order_line.product_id
|
||||
income_account = product.with_company(order_line.company_id).property_account_income_id or product.categ_id.with_company(order_line.company_id).property_account_income_categ_id
|
||||
income_account = product.with_company(order_line.company_id)._get_product_accounts()['income']
|
||||
if not income_account:
|
||||
raise UserError(_('Please define income account for this product: "%s" (id:%d).')
|
||||
% (product.name, product.id))
|
||||
|
||||
@@ -22,7 +22,7 @@ class SaleAdvancePaymentInv(models.TransientModel):
|
||||
|
||||
@api.model
|
||||
def _default_deposit_account_id(self):
|
||||
return self._default_product_id().property_account_income_id
|
||||
return self._default_product_id()._get_product_accounts()['income']
|
||||
|
||||
@api.model
|
||||
def _default_deposit_taxes_id(self):
|
||||
|
||||
@@ -101,7 +101,7 @@ class ProductProduct(models.Model):
|
||||
if 'standard_price' in vals and not self.env.context.get('disable_auto_svl'):
|
||||
for product_product in self:
|
||||
if product_product.cost_method != 'fifo':
|
||||
counterpart_account_id = product_product.property_account_expense_id.id or product_product.categ_id.property_account_expense_categ_id.id
|
||||
counterpart_account_id = product_product._get_product_accounts()['expense'].id
|
||||
product_product._change_standard_price(vals['standard_price'], counterpart_account_id)
|
||||
|
||||
return super(ProductProduct, self).write(vals)
|
||||
@@ -460,7 +460,7 @@ class ProductProduct(models.Model):
|
||||
product_accounts = {product.id: product.product_tmpl_id.get_product_accounts() for product in stock_valuation_layers.mapped('product_id')}
|
||||
for out_stock_valuation_layer in stock_valuation_layers:
|
||||
product = out_stock_valuation_layer.product_id
|
||||
expense_account = product.property_account_expense_id or product.categ_id.property_account_expense_categ_id
|
||||
expense_account = product._get_product_accounts()['expense']
|
||||
if not expense_account:
|
||||
raise UserError(_('Please define an expense account for this product: "%s" (id:%d) - or for its category: "%s".') % (product.name, product.id, self.name))
|
||||
if not product_accounts[product.id].get('stock_valuation'):
|
||||
|
||||
Reference in New Issue
Block a user