0% found this document useful (0 votes)
86 views3 pages

Join Github Today: Addons Account Models

This document is a code snippet from a product.py file in an Odoo GitHub repository. It contains code for migrating old API chunks related to accounting in product categories and templates. Key changes include adding new fields for income and expense accounts, taxes, and constraints to prevent changing unit of measure for products already used in invoices.

Uploaded by

otgntgs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views3 pages

Join Github Today: Addons Account Models

This document is a code snippet from a product.py file in an Odoo GitHub repository. It contains code for migrating old API chunks related to accounting in product categories and templates. Key changes include adding new fields for income and expense accounts, taxes, and constraints to prevent changing unit of measure for products already used in invoices.

Uploaded by

otgntgs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

3/3/2020 odoo/product.

py at 76c443eda331b75bf5dfa7ec22b8eb22e1084343 · odoo/odoo · GitHub

Dismiss
Join GitHub today
GitHub is home to over 40 million developers working together to
host and review code, manage projects, and build software together.

Sign up

Tree: 76c443eda3 Find file Copy path

odoo / addons / account / models / product.py

tivisse [MIG] account: Migrate remaining old API chuncks of code

d6e1d41 on Aug 8, 2016

4 contributors

Raw Blame History

73 lines (63 sloc) 3.6 KB

1 # -*- coding: utf-8 -*-


2
3 from odoo import api, fields, models, _
4 from odoo.exceptions import UserError
5
6
7 class ProductCategory(models.Model):
8 _inherit = "product.category"
9
10 property_account_income_categ_id = fields.Many2one('account.account', company_dependent=True,
11 string="Income Account", oldname="property_account_income_categ",

https://github.com/odoo/odoo/blob/76c443eda331b75bf5dfa7ec22b8eb22e1084343/addons/account/models/product.py#L25 1/3
3/3/2020 odoo/product.py at 76c443eda331b75bf5dfa7ec22b8eb22e1084343 · odoo/odoo · GitHub

12 domain=[('deprecated', '=', False)],


13 help="This account will be used for invoices to value sales.")
14 property_account_expense_categ_id = fields.Many2one('account.account', company_dependent=True,
15 string="Expense Account", oldname="property_account_expense_categ",
16 domain=[('deprecated', '=', False)],
17 help="This account will be used for invoices to value expenses.")
18
19 #----------------------------------------------------------
20 # Products
21 #----------------------------------------------------------
22 class ProductTemplate(models.Model):
23 _inherit = "product.template"
24
25 taxes_id = fields.Many2many('account.tax', 'product_taxes_rel', 'prod_id', 'tax_id', string='Customer Taxes',
26 domain=[('type_tax_use', '=', 'sale')])
27 supplier_taxes_id = fields.Many2many('account.tax', 'product_supplier_taxes_rel', 'prod_id', 'tax_id', string='Vendor Taxes
28 domain=[('type_tax_use', '=', 'purchase')])
29 property_account_income_id = fields.Many2one('account.account', company_dependent=True,
30 string="Income Account", oldname="property_account_income",
31 domain=[('deprecated', '=', False)],
32 help="This account will be used for invoices instead of the default one to value sales for the current product.")
33 property_account_expense_id = fields.Many2one('account.account', company_dependent=True,
34 string="Expense Account", oldname="property_account_expense",
35 domain=[('deprecated', '=', False)],
36 help="This account will be used for invoices instead of the default one to value expenses for the current product.")
37
38 @api.multi
39 def write(self, vals):
40 #TODO: really? i don't see the reason we'd need that constraint..
41 check = self.ids and 'uom_po_id' in vals
42 if check:
43 self._cr.execute("SELECT id, uom_po_id FROM product_template WHERE id IN %s", [tuple(self.ids)])
44 uoms = dict(self._cr.fetchall())
45 res = super(ProductTemplate, self).write(vals)
46 if check:
47 self._cr.execute("SELECT id, uom_po_id FROM product_template WHERE id IN %s", [tuple(self.ids)])

https://github.com/odoo/odoo/blob/76c443eda331b75bf5dfa7ec22b8eb22e1084343/addons/account/models/product.py#L25 2/3
3/3/2020 odoo/product.py at 76c443eda331b75bf5dfa7ec22b8eb22e1084343 · odoo/odoo · GitHub

48 if dict(self._cr.fetchall()) != uoms:
49 products = self.env['product.product'].search([('product_tmpl_id', 'in', self.ids)])
50 if self.env['account.move.line'].search_count([('product_id', 'in', products.ids)]):
51 raise UserError(_('You can not change the unit of measure of a product that has been already used in an acc
52 return res
53
54 @api.multi
55 def _get_product_accounts(self):
56 return {
57 'income': self.property_account_income_id or self.categ_id.property_account_income_categ_id,
58 'expense': self.property_account_expense_id or self.categ_id.property_account_expense_categ_id
59 }
60
61 @api.multi
62 def _get_asset_accounts(self):
63 res = {}
64 res['stock_input'] = False
65 res['stock_output'] = False
66 return res
67
68 @api.multi
69 def get_product_accounts(self, fiscal_pos=None):
70 accounts = self._get_product_accounts()
71 if not fiscal_pos:
72 fiscal_pos = self.env['account.fiscal.position']
73 return fiscal_pos.map_accounts(accounts)

https://github.com/odoo/odoo/blob/76c443eda331b75bf5dfa7ec22b8eb22e1084343/addons/account/models/product.py#L25 3/3

You might also like