<commit_before># -*- coding: utf-8 -*-

from odoo import api, fields, models, _
from odoo.exceptions import UserError


class ProductCategory(models.Model):
    _inherit = "product.category"

    property_account_income_categ_id = fields.Many2one('account.account', company_dependent=True,
        string="Income Account", oldname="property_account_income_categ",
        domain=[('deprecated', '=', False)],
        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", oldname="property_account_expense_categ",
        domain=[('deprecated', '=', False)],
        help="This account will be used when validating a vendor bill in periodic valuation, or when receiving products with perpetual valuation.\n For continental accounting, always set an expense account. For anglo-saxon accounting (US), you should set an expense account  for consumable, or an inventory account for products that you sell.")

#----------------------------------------------------------
# Products
#----------------------------------------------------------
class ProductTemplate(models.Model):
    _inherit = "product.template"

    taxes_id = fields.Many2many('account.tax', 'product_taxes_rel', 'prod_id', 'tax_id', string='Customer Taxes',
        domain=[('type_tax_use', '=', 'sale')])
    supplier_taxes_id = fields.Many2many('account.tax', 'product_supplier_taxes_rel', 'prod_id', 'tax_id', string='Vendor Taxes',
        domain=[('type_tax_use', '=', 'purchase')])
    property_account_income_id = fields.Many2one('account.account', company_dependent=True,
        string="Income Account", oldname="property_account_income",
        domain=[('deprecated', '=', False)],
        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", oldname="property_account_expense",
        domain=[('deprecated', '=', False)],
        help="This account will be used when validating a vendor bill in periodic valuation, or when receiving products with perpetual valuation.\n For continental accounting, always set an expense account. For anglo-saxon accounting (US), you should set an expense account  for consumable, or an inventory account for products that you sell. If the field is empty, it uses the one defined in the product category.")

    @api.multi
    def write(self, vals):
        #TODO: really? i don't see the reason we'd need that constraint..
        check = self.ids and 'uom_po_id' in vals
        if check:
            self._cr.execute("SELECT id, uom_po_id FROM product_template WHERE id IN %s", [tuple(self.ids)])
            uoms = dict(self._cr.fetchall())
        res = super(ProductTemplate, self).write(vals)
        if check:
            self._cr.execute("SELECT id, uom_po_id FROM product_template WHERE id IN %s", [tuple(self.ids)])
            if dict(self._cr.fetchall()) != uoms:
                products = self.env['product.product'].search([('product_tmpl_id', 'in', self.ids)])
                if self.env['account.move.line'].search_count([('product_id', 'in', products.ids)]):
                    raise UserError(_('You can not change the unit of measure of a product that has been already used in an account journal item. If you need to change the unit of measure, you may deactivate this product.'))
        return res

    @api.multi
    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
        }

    @api.multi
    def _get_asset_accounts(self):
        res = {}
        res['stock_input'] = False
        res['stock_output'] = False
        return res

    @api.multi
    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)
<commit_msg>[IMP] account: better tooltip on COGS account<commit_after># -*- coding: utf-8 -*-

from odoo import api, fields, models, _
from odoo.exceptions import UserError


class ProductCategory(models.Model):
    _inherit = "product.category"

    property_account_income_categ_id = fields.Many2one('account.account', company_dependent=True,
        string="Income Account", oldname="property_account_income_categ",
        domain=[('deprecated', '=', False)],
        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", oldname="property_account_expense_categ",
        domain=[('deprecated', '=', False)],
        help="This account is used when validating a vendor bill, for continental accounting or anglo-saxon without perpetual inventory valuation. For anglo-saxon accounting (US) with perpetual inventory valuation, this account is used when validating the customer invoice (set a Cost of Revenues/COGS account in this case).")

#----------------------------------------------------------
# Products
#----------------------------------------------------------
class ProductTemplate(models.Model):
    _inherit = "product.template"

    taxes_id = fields.Many2many('account.tax', 'product_taxes_rel', 'prod_id', 'tax_id', string='Customer Taxes',
        domain=[('type_tax_use', '=', 'sale')])
    supplier_taxes_id = fields.Many2many('account.tax', 'product_supplier_taxes_rel', 'prod_id', 'tax_id', string='Vendor Taxes',
        domain=[('type_tax_use', '=', 'purchase')])
    property_account_income_id = fields.Many2one('account.account', company_dependent=True,
        string="Income Account", oldname="property_account_income",
        domain=[('deprecated', '=', False)],
        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", oldname="property_account_expense",
        domain=[('deprecated', '=', False)],
        help="This account is used when validating a vendor bill, for continental accounting or anglo-saxon without perpetual inventory valuation. For anglo-saxon accounting (US) with perpetual inventory valuation, this account is used when validating the customer invoice (set a Cost of Revenues/COGS account in this case). If the field is empty, it uses the one defined in the product category.")

    @api.multi
    def write(self, vals):
        #TODO: really? i don't see the reason we'd need that constraint..
        check = self.ids and 'uom_po_id' in vals
        if check:
            self._cr.execute("SELECT id, uom_po_id FROM product_template WHERE id IN %s", [tuple(self.ids)])
            uoms = dict(self._cr.fetchall())
        res = super(ProductTemplate, self).write(vals)
        if check:
            self._cr.execute("SELECT id, uom_po_id FROM product_template WHERE id IN %s", [tuple(self.ids)])
            if dict(self._cr.fetchall()) != uoms:
                products = self.env['product.product'].search([('product_tmpl_id', 'in', self.ids)])
                if self.env['account.move.line'].search_count([('product_id', 'in', products.ids)]):
                    raise UserError(_('You can not change the unit of measure of a product that has been already used in an account journal item. If you need to change the unit of measure, you may deactivate this product.'))
        return res

    @api.multi
    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
        }

    @api.multi
    def _get_asset_accounts(self):
        res = {}
        res['stock_input'] = False
        res['stock_output'] = False
        return res

    @api.multi
    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)

{'fraction_non_alphanumeric': 0.13352941176470587, 'fraction_numerical': 0.0016470588235294118, 'mean_word_length': 3.223050173869846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4129344', 'n_tokens_mistral': 2393, 'n_tokens_neox': 2333, 'n_words': 678}