Remove default account, add account template and config wizard to create chart
of account.
This commit is contained in:
1 parent
c3fe7eca74
commit
2fa491d341
4 files changed
+356
-57
No files matched your search
+189
@@ -91,6 +91,72 @@ class Type(OSV):
|
||||
Type()
|
||||
|
||||
|
||||
class AccountTemplate(OSV):
|
||||
'Account Template'
|
||||
_name = 'account.account.template'
|
||||
_description = __doc__
|
||||
_order = 'code, id'
|
||||
_parent_name = 'parents'
|
||||
|
||||
name = fields.Char('Name', size=None, required=True, translate=True,
|
||||
select=1)
|
||||
code = fields.Char('Code', size=None, select=1)
|
||||
type = fields.Many2One('account.account.type', 'Type', required=True,
|
||||
domain=[('account_type', '=', True)])
|
||||
parents = fields.Many2Many('account.account.template',
|
||||
'account_account_template_rel', 'child', 'parent', 'Parents')
|
||||
childs = fields.Many2Many('account.account.template',
|
||||
'account_account_template_rel', 'parent', 'child', 'Childs')
|
||||
reconcile = fields.Boolean('Reconcile')
|
||||
close_method = fields.Selection([
|
||||
('none', 'None'),
|
||||
('balance', 'Balance'),
|
||||
('detail', 'Detail'),
|
||||
('unreconciled', 'Unreconciled'),
|
||||
], 'Deferral method', required=True)
|
||||
|
||||
def _get_account_value(self, cursor, user, template, context=None):
|
||||
res = {}
|
||||
res['name'] = template.name
|
||||
res['code'] = template.code
|
||||
res['type'] = template.type.id
|
||||
res['reconcile'] = template.reconcile
|
||||
res['close_method'] = template.close_method
|
||||
res['taxes'] = [('add', x.id) for x in template.taxes]
|
||||
return res
|
||||
|
||||
def create_account(self, cursor, user, template, company_id, context=None,
|
||||
template2account=None):
|
||||
account_obj = self.pool.get('account.account')
|
||||
|
||||
if template2account is None:
|
||||
template2account = {}
|
||||
|
||||
if isinstance(template, (int, long)):
|
||||
template = self.browse(cursor, user, template, context=context)
|
||||
|
||||
if template.id not in template2account:
|
||||
vals = self._get_account_value(cursor, user, template, context=context)
|
||||
vals['company'] = company_id
|
||||
|
||||
new_id = account_obj.create(cursor, user, vals, context=context)
|
||||
template2account[template.id] = new_id
|
||||
else:
|
||||
new_id = template2account[template.id]
|
||||
|
||||
new_childs = []
|
||||
for child in template.childs:
|
||||
new_childs.append(self.create_account(cursor, user, child,
|
||||
company_id, context=context, template2account=template2account))
|
||||
if new_childs:
|
||||
account_obj.write(cursor, user, new_childs, {
|
||||
'parents': [('add', new_id)],
|
||||
}, context=context)
|
||||
return new_id
|
||||
|
||||
AccountTemplate()
|
||||
|
||||
|
||||
class Account(OSV):
|
||||
'Account'
|
||||
_name = 'account.account'
|
||||
@@ -962,3 +1028,126 @@ class OpenIncomeStatement(Wizard):
|
||||
return res
|
||||
|
||||
OpenIncomeStatement()
|
||||
|
||||
|
||||
class CreateChartAccountInit(WizardOSV):
|
||||
_name = 'account.account.create_chart_account.init'
|
||||
|
||||
CreateChartAccountInit()
|
||||
|
||||
|
||||
class CreateChartAccountAccount(WizardOSV):
|
||||
_name = 'account.account.create_chart_account.account'
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
account_template = fields.Many2One('account.account.template',
|
||||
'Account Template', required=True, domain=[('parents', '=', False)])
|
||||
|
||||
CreateChartAccountAccount()
|
||||
|
||||
|
||||
class CreateChartAccountPropertites(WizardOSV):
|
||||
_name = 'account.account.create_chart_account.properties'
|
||||
company = fields.Many2One('company.company', 'Company')
|
||||
account_receivable = fields.Many2One('account.account',
|
||||
'Default Receivable Account',
|
||||
domain="[('company', '=', company)]")
|
||||
account_payable = fields.Many2One('account.account',
|
||||
'Default Payable Account',
|
||||
domain="[('company', '=', company)]")
|
||||
|
||||
CreateChartAccountPropertites()
|
||||
|
||||
|
||||
class CreateChartAccount(Wizard):
|
||||
'Create chart account from template'
|
||||
_name = 'account.account.create_chart_account'
|
||||
states = {
|
||||
'init': {
|
||||
'result': {
|
||||
'type': 'form',
|
||||
'object': 'account.account.create_chart_account.init',
|
||||
'state': [
|
||||
('end', 'Cancel', 'gtk-cancel'),
|
||||
('account', 'Ok', 'gtk-ok', True),
|
||||
],
|
||||
},
|
||||
},
|
||||
'account': {
|
||||
'result': {
|
||||
'type': 'form',
|
||||
'object': 'account.account.create_chart_account.account',
|
||||
'state': [
|
||||
('end', 'Cancel', 'gtk-cancel'),
|
||||
('create_account', 'Create', 'gtk-ok', True),
|
||||
],
|
||||
},
|
||||
},
|
||||
'create_account': {
|
||||
'actions': ['_action_create_account'],
|
||||
'result': {
|
||||
'type': 'form',
|
||||
'object': 'account.account.create_chart_account.properties',
|
||||
'state': [
|
||||
('end', 'Cancel', 'gtk-cancel'),
|
||||
('create_properties', 'Create', 'gtk-ok', True),
|
||||
],
|
||||
},
|
||||
},
|
||||
'create_properties': {
|
||||
'result': {
|
||||
'type': 'action',
|
||||
'action': '_action_create_properties',
|
||||
'state': 'end',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
def _action_create_account(self, cursor, user, datas, context=None):
|
||||
account_template_obj = self.pool.get('account.account.template')
|
||||
account_template_obj.create_account(cursor, user,
|
||||
datas['form']['account_template'], datas['form']['company'],
|
||||
context=context)
|
||||
return {'company': datas['form']['company']}
|
||||
|
||||
def _action_create_properties(self, cursor, user, datas, context=None):
|
||||
property_obj = self.pool.get('ir.property')
|
||||
model_field_obj = self.pool.get('ir.model.field')
|
||||
|
||||
account_receivable_field_id = model_field_obj.search(cursor, user, [
|
||||
('model.model', '=', 'partner.partner'),
|
||||
('name', '=', 'account_receivable'),
|
||||
], limit=1, context=context)[0]
|
||||
property_ids = property_obj.search(cursor, user, [
|
||||
('field', '=', account_receivable_field_id),
|
||||
('res', '=', False),
|
||||
('company', '=', datas['form']['company']),
|
||||
], context=context)
|
||||
property_obj.unlink(cursor, user, property_ids, context=context)
|
||||
property_obj.create(cursor, user, {
|
||||
'name': 'account_receivable',
|
||||
'field': account_receivable_field_id,
|
||||
'value': 'account.account,' + \
|
||||
str(datas['form']['account_receivable']),
|
||||
'company': datas['form']['company'],
|
||||
}, context=context)
|
||||
|
||||
account_payable_field_id = model_field_obj.search(cursor, user, [
|
||||
('model.model', '=', 'partner.partner'),
|
||||
('name', '=', 'account_payable'),
|
||||
], limit=1, context=context)[0]
|
||||
property_ids = property_obj.search(cursor, user, [
|
||||
('field', '=', account_payable_field_id),
|
||||
('res', '=', False),
|
||||
('company', '=', datas['form']['company']),
|
||||
], context=context)
|
||||
property_obj.unlink(cursor, user, property_ids, context=context)
|
||||
property_obj.create(cursor, user, {
|
||||
'name': 'account_payable',
|
||||
'field': account_payable_field_id,
|
||||
'value': 'account.account,' + \
|
||||
str(datas['form']['account_payable']),
|
||||
'company': datas['form']['company'],
|
||||
}, context=context)
|
||||
return {}
|
||||
|
||||
CreateChartAccount()
|
||||
+158
-54
@@ -198,6 +198,164 @@
|
||||
<field name="account_type" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="account_template_view_form">
|
||||
<field name="model">account.account.template</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Account Template" col="6">
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<label name="code"/>
|
||||
<field name="code"/>
|
||||
<label name="type"/>
|
||||
<field name="type" widget="selection"/>
|
||||
<label name="close_method"/>
|
||||
<field name="close_method"/>
|
||||
<label name="reconcile"/>
|
||||
<field name="reconcile"/>
|
||||
<separator name="parents" colspan="6"/>
|
||||
<field name="parents" colspan="6"/>
|
||||
<separator name="taxes" colspan="6"/>
|
||||
<field name="taxes" colspan="6"/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="account_template_view_tree">
|
||||
<field name="model">account.account.template</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="field_childs">childs</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<tree string="Account Templates">
|
||||
<field name="name" select="1"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="type" select="2"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window" id="act_account_template_tree">
|
||||
<field name="name">Account Templates</field>
|
||||
<field name="res_model">account.account.template</field>
|
||||
<field name="view_type">tree</field>
|
||||
<field name="domain">[('parents', '=', False)]</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_account_template_tree_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="account_template_view_tree"/>
|
||||
<field name="act_window" ref="act_account_template_tree"/>
|
||||
</record>
|
||||
<menuitem parent="menu_general_account_configuration"
|
||||
action="act_account_template_tree" id="menu_account_template_tree"/>
|
||||
<record model="ir.model.access" id="access_account_template">
|
||||
<field name="model" search="[('model', '=', 'account.account.template')]"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_unlink" eval="False"/>
|
||||
</record>
|
||||
<record model="account.account.template" id="account_template_root">
|
||||
<field name="name">Minimal Account Chart</field>
|
||||
<field name="close_method">none</field>
|
||||
<field name="type" ref="account_type_view"/>
|
||||
</record>
|
||||
<record model="account.account.template" id="account_template_receivable">
|
||||
<field name="name">Main Receivable</field>
|
||||
<field name="type" ref="account_type_asset_current_receivable"/>
|
||||
<field name="reconcile" eval="True"/>
|
||||
<field name="close_method">unreconciled</field>
|
||||
<field name="parents" eval="[('add', ref('account_template_root'))]"/>
|
||||
</record>
|
||||
<record model="account.account.template" id="account_template_payable">
|
||||
<field name="name">Main Payable</field>
|
||||
<field name="type" ref="account_type_liability_current_payable"/>
|
||||
<field name="reconcile" eval="True"/>
|
||||
<field name="close_method">unreconciled</field>
|
||||
<field name="parents" eval="[('add', ref('account_template_root'))]"/>
|
||||
</record>
|
||||
<record model="account.account.template" id="account_template_revenue">
|
||||
<field name="name">Main Revenue</field>
|
||||
<field name="type" ref="account_type_revenue"/>
|
||||
<field name="close_method">none</field>
|
||||
<field name="parents" eval="[('add', ref('account_template_root'))]"/>
|
||||
</record>
|
||||
<record model="account.account.template" id="account_template_expense">
|
||||
<field name="name">Main Expense</field>
|
||||
<field name="type" ref="account_type_expense"/>
|
||||
<field name="close_method">none</field>
|
||||
<field name="parents" eval="[('add', ref('account_template_root'))]"/>
|
||||
</record>
|
||||
<record model="account.account.template" id="account_template_cash">
|
||||
<field name="name">Main Cash</field>
|
||||
<field name="type" ref="account_type_asset_current_cash"/>
|
||||
<field name="close_method">balance</field>
|
||||
<field name="parents" eval="[('add', ref('account_template_root'))]"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="account_create_chart_account_init_view_form">
|
||||
<field name="model">account.account.create_chart_account.init</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Create Chart of Account" col="2">
|
||||
<separator string="Create Chart of Account" align="0.0"
|
||||
colspan="2"/>
|
||||
<image name="gtk-info"/>
|
||||
<group col="1">
|
||||
<label string="You can now create a chart of account for your company"
|
||||
align="0.0"/>
|
||||
<label string="by selecting a chart of account template."
|
||||
align="0.0"/>
|
||||
</group>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="account_create_chart_account_account_view_form">
|
||||
<field name="model">account.account.create_chart_account.account</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Create Chart of Account" col="2">
|
||||
<label name="company"/>
|
||||
<field name="company"/>
|
||||
<label name="account_template"/>
|
||||
<field name="account_template"/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="account_create_chart_account_properties_view_form">
|
||||
<field name="model">account.account.create_chart_account.properties</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Create Default Properties" col="2">
|
||||
<label name="account_receivable"/>
|
||||
<field name="account_receivable"/>
|
||||
<label name="account_payable"/>
|
||||
<field name="account_payable"/>
|
||||
<field name="company" invisible="1"/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.wizard" id="wizard_create_chart_account">
|
||||
<field name="name">Create Chart of Account from Template</field>
|
||||
<field name="wiz_name">account.account.create_chart_account</field>
|
||||
</record>
|
||||
<menuitem parent="menu_general_account_configuration"
|
||||
action="wizard_create_chart_account" id="menu_create_chart_account"/>
|
||||
<record model="ir.module.module.config_wizard.item"
|
||||
id="config_wizard_item_chart_account">
|
||||
<field name="name">account.account.create_chart_account</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="account_view_form">
|
||||
<field name="model">account.account</field>
|
||||
<field name="type">form</field>
|
||||
@@ -333,60 +491,6 @@
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_unlink" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account" id="account_root">
|
||||
<field name="name">Root</field>
|
||||
<field name="close_method">none</field>
|
||||
<field name="type" ref="account_type_view"/>
|
||||
<field name="company" ref="company.main"/>
|
||||
</record>
|
||||
<record model="account.account" id="account_receivable">
|
||||
<field name="name">Main Receivable</field>
|
||||
<field name="type" ref="account_type_asset_current_receivable"/>
|
||||
<field name="company" ref="company.main"/>
|
||||
<field name="reconcile" eval="True"/>
|
||||
<field name="close_method">unreconciled</field>
|
||||
<field name="parents" eval="[('add', ref('account_root'))]"/>
|
||||
</record>
|
||||
<record model="account.account" id="account_payable">
|
||||
<field name="name">Main Payable</field>
|
||||
<field name="type" ref="account_type_liability_current_payable"/>
|
||||
<field name="company" ref="company.main"/>
|
||||
<field name="reconcile" eval="True"/>
|
||||
<field name="close_method">unreconciled</field>
|
||||
<field name="parents" eval="[('add', ref('account_root'))]"/>
|
||||
</record>
|
||||
<record model="account.account" id="account_revenue">
|
||||
<field name="name">Main Revenue</field>
|
||||
<field name="type" ref="account_type_revenue"/>
|
||||
<field name="company" ref="company.main"/>
|
||||
<field name="parents" eval="[('add', ref('account_root'))]"/>
|
||||
</record>
|
||||
<record model="account.account" id="account_expense">
|
||||
<field name="name">Main Expense</field>
|
||||
<field name="type" ref="account_type_expense"/>
|
||||
<field name="company" ref="company.main"/>
|
||||
<field name="parents" eval="[('add', ref('account_root'))]"/>
|
||||
</record>
|
||||
<record model="account.account" id="account_cash">
|
||||
<field name="name">Main Cash</field>
|
||||
<field name="type" ref="account_type_asset_current_cash"/>
|
||||
<field name="company" ref="company.main"/>
|
||||
<field name="parents" eval="[('add', ref('account_root'))]"/>
|
||||
</record>
|
||||
<record model="ir.property" id="property_account_receivable">
|
||||
<field name="name">account_receivable</field>
|
||||
<field name="field"
|
||||
search="[('model.model', '=', 'partner.partner'), ('name', '=', 'account_receivable')]"/>
|
||||
<field name="value" eval="'account.account,' + str(ref('account_receivable'))"/>
|
||||
<field name="company" ref="company.main"/>
|
||||
</record>
|
||||
<record model="ir.property" id="property_account_payable">
|
||||
<field name="name">account_payable</field>
|
||||
<field name="field"
|
||||
search="[('model.model', '=', 'partner.partner'), ('name', '=', 'account_payable')]"/>
|
||||
<field name="value" eval="'account.account,' + str(ref('account_payable'))"/>
|
||||
<field name="company" ref="company.main"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="open_chart_account_init_view_form">
|
||||
<field name="model">account.account.open_chart_account.init</field>
|
||||
|
||||
@@ -151,8 +151,5 @@
|
||||
<field name="rounding" eval="0.01"/>
|
||||
<field name="digits" eval="2"/>
|
||||
</record>
|
||||
<record model="company.company" id="company.main">
|
||||
<field name="currency" ref="eur"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -487,6 +487,15 @@ class OpenCode(Wizard):
|
||||
OpenCode()
|
||||
|
||||
|
||||
class AccountTemplate(OSV):
|
||||
_name = 'account.account.template'
|
||||
taxes = fields.Many2Many('account.tax', 'account_account_template_tax_rel',
|
||||
'account', 'tax', 'Default Taxes',
|
||||
domain="[('parent', '=', False)]")
|
||||
|
||||
AccountTemplate()
|
||||
|
||||
|
||||
class Account(OSV):
|
||||
_name = 'account.account'
|
||||
taxes = fields.Many2Many('account.tax', 'account_account_tax_rel',
|
||||
|
||||
Reference in new issue
Block a user