[IMP] stock_account: added property stock accounts to remove dependencies

This commit is contained in:
pvy
2015-06-12 10:10:28 +02:00
parent f9735c1b78
commit 69ff9d1eaa
8 changed files with 88 additions and 58 deletions
+13
View File
@@ -83,6 +83,9 @@ class AccountChartTemplate(models.Model):
property_account_income_categ = fields.Many2one('account.account.template', string='Income Category Account')
property_account_expense = fields.Many2one('account.account.template', string='Expense Account on Product Template')
property_account_income = fields.Many2one('account.account.template', string='Income Account on Product Template')
property_stock_account_input_categ = fields.Many2one('account.account.template')
property_stock_account_output_categ = fields.Many2one('account.account.template')
property_stock_valuation_account_id = fields.Many2one('account.account.template')
@api.one
def try_loading_for_current_company(self):
@@ -228,6 +231,16 @@ class AccountChartTemplate(models.Model):
else:
#create the property
PropertyObj.create(vals)
stock_properties = [
'property_stock_account_input_categ',
'property_stock_account_output_categ',
'property_stock_valuation_account_id',
]
for stock_property in stock_properties:
account = getattr(self, stock_property)
value = account and acc_template_ref[account.id] or False
if value:
company.write({stock_property: value})
return True
@api.multi
+3
View File
@@ -31,6 +31,9 @@ class ResCompany(models.Model):
expense_currency_exchange_account_id = fields.Many2one('account.account', related='currency_exchange_journal_id.default_debit_account_id',
string="Loss Exchange Rate Account", domain="[('internal_type', '=', 'other'), ('deprecated', '=', False), ('company_id', '=', id)]")
anglo_saxon_accounting = fields.Boolean(string="Use anglo-saxon accounting")
property_stock_account_input_categ = fields.Many2one('account.account')
property_stock_account_output_categ = fields.Many2one('account.account')
property_stock_valuation_account_id = fields.Many2one('account.account')
@api.multi
def compute_fiscalyear_dates(self, date):
-1
View File
@@ -39,7 +39,6 @@ position.
'account',
'base_iban',
'base_vat',
'stock',
],
'data': [
'account_chart_en.xml',
+1 -1
View File
@@ -754,7 +754,7 @@
<record id="chart512302_en" model="account.account.template">
<field name="code">512302</field>
<field name="user_type" ref="account.data_account_type_expe
<field name="user_type" ref="account.data_account_type_expenses"/>
<field name="name">Employment Insurance</field>
</record>
+3 -20
View File
@@ -12,29 +12,12 @@
<field name="property_account_payable" ref="chart2111_en"/>
<field name="property_account_income_categ" ref="chart411_en"/>
<field name="property_account_expense_categ" ref="chart5111_en"/>
<field name="property_stock_account_input_categ" ref="chart2141_en"/>
<field name="property_stock_account_output_categ" ref="chart1145_en"/>
<field name="property_stock_valuation_account_id" ref="chart1141_en"/>
<field name="currency_id" ref="base.CAD"/>
<field name="use_anglo_saxon" eval="True"/>
</record>
<record id="stock.property_stock_account_input_categ" model="ir.property">
<field name="fields_id" search="[('model','=','product.category'),('name','=','property_stock_account_input_categ')]"/>
<field eval="'account.account,'+str(ref('chart2141_en'))" model="account.account" name="value"/>
<field eval="'product.category,'+str(ref('product.product_category_all'))" model="product.category" name="res_id"/>
</record>
<record id="stock.property_stock_account_output_categ" model="ir.property">
<field name="fields_id" search="[('model','=','product.category'),('name','=','property_stock_account_output_categ')]"/>
<field eval="'account.account,'+str(ref('chart1145_en'))" model="account.account" name="value"/>
<field eval="'product.category,'+str(ref('product.product_category_all'))" model="product.category" name="res_id"/>
</record>
<record id="property_stock_valuation_account_id_en" model="ir.property">
<field name="name">property_stock_valuation_account_id</field>
<field name="fields_id" search="[('model','=','product.category'),('name','=','property_stock_valuation_account_id')]"/>
<field name="company_id" ref="base.main_company"/>
<field eval="'account.account,'+str(ref('chart1141_en'))" model="account.account" name="value"/>
<field eval="'product.category,'+str(ref('product.product_category_all'))" model="product.category" name="res_id"/>
</record>
</data>
</openerp>
+17 -34
View File
@@ -1,39 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<data>
<!-- Chart template -->
<record id="ca_fr_chart_template_fr" model="account.chart.template">
<field name="name">Canada - Plan comptable pour les provinces francophones</field>
<field name="account_root_id" ref="chart0_fr"/>
<field name="bank_account_view_id" ref="chart111_fr"/>
<field name="property_account_receivable" ref="chart1151_fr"/>
<field name="property_account_payable" ref="chart2111_fr"/>
<field name="property_account_income_categ" ref="chart411_fr"/>
<field name="property_account_expense_categ" ref="chart5111_fr"/>
<field name="currency_id" ref="base.CAD"/>
<field name="use_anglo_saxon" eval="True"/>
</record>
<!-- Chart template -->
<record id="ca_fr_chart_template_fr" model="account.chart.template">
<field name="name">Canada - Plan comptable pour les provinces francophones</field>
<field name="account_root_id" ref="chart0_fr"/>
<field name="bank_account_view_id" ref="chart111_fr"/>
<field name="property_account_receivable" ref="chart1151_fr"/>
<field name="property_account_payable" ref="chart2111_fr"/>
<field name="property_account_income_categ" ref="chart411_fr"/>
<field name="property_account_expense_categ" ref="chart5111_fr"/>
<field name="property_stock_account_input_categ" ref="chart2171_fr"/>
<field name="property_stock_account_output_categ" ref="chart1145_fr"/>
<field name="property_stock_valuation_account_id" ref="chart1141_fr"/>
<field name="currency_id" ref="base.CAD"/>
<field name="use_anglo_saxon" eval="True"/>
</record>
<record id="stock.property_stock_account_input_categ" model="ir.property">
<field name="fields_id" search="[('model','=','product.category'),('name','=','property_stock_account_input_categ')]"/>
<field eval="'account.account,'+str(ref('chart2171_fr'))" model="account.account" name="value"/>
<field eval="'product.category,'+str(ref('product.product_category_all'))" model="product.category" name="res_id"/>
</record>
<record id="stock.property_stock_account_output_categ" model="ir.property">
<field name="fields_id" search="[('model','=','product.category'),('name','=','property_stock_account_output_categ')]"/>
<field eval="'account.account,'+str(ref('chart1145_fr'))" model="account.account" name="value"/>
<field eval="'product.category,'+str(ref('product.product_category_all'))" model="product.category" name="res_id"/>
</record>
<record id="property_stock_valuation_account_id" model="ir.property">
<field name="name">property_stock_valuation_account_id</field>
<field name="fields_id" search="[('model','=','product.category'),('name','=','property_stock_valuation_account_id')]"/>
<field name="company_id" ref="base.main_company"/>
<field eval="'account.account,'+str(ref('chart1141_fr'))" model="account.account" name="value"/>
<field eval="'product.category,'+str(ref('product.product_category_all'))" model="product.category" name="res_id"/>
</record>
</data>
</data>
</openerp>
+28 -2
View File
@@ -425,7 +425,7 @@ class AccountChartTemplate(models.Model):
@api.multi
def generate_properties(self, acc_template_ref, company, property_list=None):
super(AccountChartTemplate, self).generate_properties(acc_template_ref=acc_template_ref, company=company)
PropertyObj = self.env['ir.property']
PropertyObj = self.env['ir.property'] # Property Stock Journal
value = self.env['account.journal'].search([('company_id', '=', company.id), ('code', '=', 'STJ'), ('type', '=', 'general')], limit=1)
if value:
field = self.env['ir.model.fields'].search([('name', '=', 'property_stock_journal'), ('model', '=', 'product.category'), ('relation', '=', 'account.journal')], limit=1)
@@ -442,4 +442,30 @@ class AccountChartTemplate(models.Model):
else:
#create the property
PropertyObj.create(vals)
return True
todo_list = [ # Property Stock Accounts
'property_stock_account_input_categ',
'property_stock_account_output_categ',
'property_stock_valuation_account_id',
]
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,
'res_id': 'product.category,'+str(self.env['ir.model.data'].xmlid_to_res_id('product.product_category_all')),
}
properties = PropertyObj.search([('name', '=', record), ('company_id', '=', company.id)])
if properties:
#the property exist: modify it
properties.write(vals)
else:
#create the property
PropertyObj.create(vals)
return True
@@ -26,3 +26,26 @@
'value': 'account.journal,' + str(journal_id)}
PropertyObj.create(cr, uid, vals)
todo_list = [ # Property Stock Accounts
'property_stock_account_input_categ',
'property_stock_account_output_categ',
'property_stock_valuation_account_id',
]
company = company_obj.browse(cr, uid, company_id)
for record in todo_list:
account = getattr(company, record)
value = account and 'account.account,' + str(account.id) or False
if value:
field_id = self.pool.get('ir.model.fields').search(cr, uid, [('name', '=', record), ('model', '=', 'product.category'), ('relation', '=', 'account.account')], limit=1)[0]
vals = {
'name': record,
'company_id': company_id,
'fields_id': field_id,
'value': value,
'res_id': 'product.category,'+str(ref('product.product_category_all')),
}
properties = PropertyObj.search(cr, uid, [('name', '=', record), ('company_id', '=', company.id), ('value_reference', '!=', False)])
if not properties:
#create the property
PropertyObj.create(cr, uid, vals)