Before this fix, a cash basis OSS tax used together with a product using the "non-EU origin" tag didn't appear properly in the OSS import report. This was due to the fact the product tag was not copied on the cash basis move: it only appeared on the invoice, on non exigible lines. To fix that, we make the choice to keep the product tag as markup on the invoice, and to copy it to the cash basis lines created from move lines containing this tag. We therefore need a non-ambiguous way to identify account.account.tag objects that are used on products, since we don't want to copy tags used by taxes. Hence, we introduct a new value for the 'applicability' field of account.account.tag, limitating their use to products. closes odoo/odoo#76626 X-original-commit: 0dd712b876844c3e342447e4cf26b324fcaffc37 Related: odoo/enterprise#20916 Signed-off-by: Laurent Smet <smetl@users.noreply.github.com> Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
86 lines
4.2 KiB
Python
86 lines
4.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import api, fields, models, _
|
|
from odoo.tools import format_amount
|
|
|
|
ACCOUNT_DOMAIN = "['&', '&', '&', ('deprecated', '=', False), ('internal_type','=','other'), ('company_id', '=', current_company_id), ('is_off_balance', '=', False)]"
|
|
|
|
class ProductCategory(models.Model):
|
|
_inherit = "product.category"
|
|
|
|
property_account_income_categ_id = fields.Many2one('account.account', company_dependent=True,
|
|
string="Income Account",
|
|
domain=ACCOUNT_DOMAIN,
|
|
help="This account will be used when validating a customer invoice.")
|
|
property_account_expense_categ_id = fields.Many2one('account.account', company_dependent=True,
|
|
string="Expense Account",
|
|
domain=ACCOUNT_DOMAIN,
|
|
help="The expense is accounted for when a vendor bill is validated, except in anglo-saxon accounting with perpetual inventory valuation in which case the expense (Cost of Goods Sold account) is recognized at the customer invoice validation.")
|
|
|
|
#----------------------------------------------------------
|
|
# Products
|
|
#----------------------------------------------------------
|
|
class ProductTemplate(models.Model):
|
|
_inherit = "product.template"
|
|
|
|
taxes_id = fields.Many2many('account.tax', 'product_taxes_rel', 'prod_id', 'tax_id', help="Default taxes used when selling the product.", string='Customer Taxes',
|
|
domain=[('type_tax_use', '=', 'sale')], default=lambda self: self.env.company.account_sale_tax_id)
|
|
tax_string = fields.Char(compute='_compute_tax_string')
|
|
supplier_taxes_id = fields.Many2many('account.tax', 'product_supplier_taxes_rel', 'prod_id', 'tax_id', string='Vendor Taxes', help='Default taxes used when buying the product.',
|
|
domain=[('type_tax_use', '=', 'purchase')], default=lambda self: self.env.company.account_purchase_tax_id)
|
|
property_account_income_id = fields.Many2one('account.account', company_dependent=True,
|
|
string="Income Account",
|
|
domain=ACCOUNT_DOMAIN,
|
|
help="Keep this field empty to use the default value from the product category.")
|
|
property_account_expense_id = fields.Many2one('account.account', company_dependent=True,
|
|
string="Expense Account",
|
|
domain=ACCOUNT_DOMAIN,
|
|
help="Keep this field empty to use the default value from the product category. If anglo-saxon accounting with automated valuation method is configured, the expense account on the product category will be used.")
|
|
account_tag_ids = fields.Many2many(
|
|
string="Account Tags",
|
|
comodel_name='account.account.tag',
|
|
domain="[('applicability', '=', 'products')]",
|
|
help="Tags to be set on the base and tax journal items created for this product.")
|
|
|
|
def _get_product_accounts(self):
|
|
return {
|
|
'income': self.property_account_income_id or self.categ_id.property_account_income_categ_id,
|
|
'expense': self.property_account_expense_id or self.categ_id.property_account_expense_categ_id
|
|
}
|
|
|
|
def _get_asset_accounts(self):
|
|
res = {}
|
|
res['stock_input'] = False
|
|
res['stock_output'] = False
|
|
return res
|
|
|
|
def get_product_accounts(self, fiscal_pos=None):
|
|
accounts = self._get_product_accounts()
|
|
if not fiscal_pos:
|
|
fiscal_pos = self.env['account.fiscal.position']
|
|
return fiscal_pos.map_accounts(accounts)
|
|
|
|
@api.depends('taxes_id', 'list_price')
|
|
def _compute_tax_string(self):
|
|
for record in self:
|
|
currency = record.currency_id
|
|
res = record.taxes_id.compute_all(record.list_price)
|
|
joined = []
|
|
included = res['total_included']
|
|
if currency.compare_amounts(included, record.list_price):
|
|
joined.append(_('%s Incl. Taxes', format_amount(self.env, included, currency)))
|
|
excluded = res['total_excluded']
|
|
if currency.compare_amounts(excluded, record.list_price):
|
|
joined.append(_('%s Excl. Taxes', format_amount(self.env, excluded, currency)))
|
|
if joined:
|
|
record.tax_string = f"(= {', '.join(joined)})"
|
|
else:
|
|
record.tax_string = " "
|
|
|
|
|
|
class ProductProduct(models.Model):
|
|
_inherit = "product.product"
|
|
|
|
def _get_product_accounts(self):
|
|
return self.product_tmpl_id._get_product_accounts()
|