Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(purchase): add price difference valuation account to coa (TODO) #40158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions addons/account/models/chart_template.py
Expand Up @@ -107,6 +107,7 @@ class AccountChartTemplate(models.Model):
property_stock_account_input_categ_id = fields.Many2one('account.account.template', string="Input Account for Stock Valuation")
property_stock_account_output_categ_id = fields.Many2one('account.account.template', string="Output Account for Stock Valuation")
property_stock_valuation_account_id = fields.Many2one('account.account.template', string="Account Template for Stock Valuation")
property_account_creditor_price_difference_categ = fields.Many2one('account.account.template', string="Account Template for Price Difference Account")
property_tax_payable_account_id = fields.Many2one('account.account.template', string="Tax current account (payable)")
property_tax_receivable_account_id = fields.Many2one('account.account.template', string="Tax current account (receivable)")
property_advance_tax_payment_account_id = fields.Many2one('account.account.template', string="Advance tax payment account")
Expand Down Expand Up @@ -477,6 +478,7 @@ def generate_properties(self, acc_template_ref, company):
'property_stock_account_input_categ_id',
'property_stock_account_output_categ_id',
'property_stock_valuation_account_id',
'property_account_creditor_price_difference_categ',
]
for stock_property in stock_properties:
account = getattr(self, stock_property)
Expand Down
1 change: 1 addition & 0 deletions addons/account/models/company.py
Expand Up @@ -62,6 +62,7 @@ class ResCompany(models.Model):
property_stock_account_input_categ_id = fields.Many2one('account.account', string="Input Account for Stock Valuation")
property_stock_account_output_categ_id = fields.Many2one('account.account', string="Output Account for Stock Valuation")
property_stock_valuation_account_id = fields.Many2one('account.account', string="Account Template for Stock Valuation")
property_account_creditor_price_difference_categ = fields.Many2one('account.account', string="Account Template for Price Difference Account")
bank_journal_ids = fields.One2many('account.journal', 'company_id', domain=[('type', '=', 'bank')], string='Bank Journals')
tax_exigibility = fields.Boolean(string='Use Cash Basis')
account_bank_reconciliation_start = fields.Date(string="Bank Reconciliation Threshold", help="""The bank reconciliation widget won't ask to reconcile payments older than this date.
Expand Down
42 changes: 42 additions & 0 deletions addons/purchase/__init__.py
Expand Up @@ -4,3 +4,45 @@
from . import controllers
from . import models
from . import report

from odoo import api, SUPERUSER_ID, _, tools

def _configure_accounts(cr, registry):
"""Setting property field (if needed)"""

env = api.Environment(cr, SUPERUSER_ID, {})

# if we already have a coa installed, create set property field
company_ids = env['res.company'].search([('chart_template_id', '!=', False)])

for company_id in company_ids:

# Property Stock Accounts
todo_list = [
'property_account_creditor_price_difference_categ',
]

for record in todo_list:
account = getattr(company_id, record)
value = account and 'account.account,' + str(account.id) or False
if value:
field_id = env['ir.model.fields'].search([
('name', '=', record),
('model', '=', 'product.category'),
('relation', '=', 'account.account')
], limit=1).id
vals = {
'name': record,
'company_id': company_id.id,
'fields_id': field_id,
'value': value,
}
properties = env['ir.property'].search([
('name', '=', record),
('company_id', '=', company_id.id),
])
if properties:
properties.write(vals)
else:
# create the property
env['ir.property'].create(vals)
1 change: 1 addition & 0 deletions addons/purchase/__manifest__.py
Expand Up @@ -34,4 +34,5 @@
'installable': True,
'auto_install': False,
'application': True,
'post_init_hook': '_configure_accounts',
}
1 change: 1 addition & 0 deletions addons/purchase/models/__init__.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import account_chart_template
from . import account_invoice
from . import purchase
from . import product
Expand Down
41 changes: 41 additions & 0 deletions addons/purchase/models/account_chart_template.py
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, models, _

import logging
_logger = logging.getLogger(__name__)


class AccountChartTemplate(models.Model):
_inherit = "account.chart.template"


@api.multi
def generate_properties(self, acc_template_ref, company, property_list=None):
res = super(AccountChartTemplate, self).generate_properties(acc_template_ref=acc_template_ref, company=company)
PropertyObj = self.env['ir.property'] # Property Stock Journal

todo_list = [ # Property Stock Accounts
'property_account_creditor_price_difference_categ',
]
for record in todo_list:
account = getattr(self, record)
value = account and 'account.account,' + str(acc_template_ref[account.id]) or False
if value:
field = self.env['ir.model.fields'].search([('name', '=', record), ('model', '=', 'product.category'), ('relation', '=', 'account.account')], limit=1)
vals = {
'name': record,
'company_id': company.id,
'fields_id': field.id,
'value': value,
}
properties = PropertyObj.search([('name', '=', record), ('company_id', '=', company.id)], limit=1)
if not properties:
# create the property
PropertyObj.create(vals)
elif not properties.value_reference:
# update the property if False
properties.write(vals)

return res