2
0

[12.0][ENH] account_spreaad_cost_revenue, add optional expense/revenue account

This commit is contained in:
Kitti U 2020-04-21 18:07:14 +07:00 committed by Andrea Stirpe
parent c0a2232d2e
commit 7daae7a387
9 changed files with 103 additions and 24 deletions

View File

@ -44,6 +44,9 @@ class AccountSpread(models.Model):
default='month',
help="Period length for the entries",
required=True)
use_invoice_line_account = fields.Boolean(
string="Use invoice line's account",
)
credit_account_id = fields.Many2one(
'account.account',
string='Credit Account',

View File

@ -23,10 +23,18 @@ class AccountSpreadTemplate(models.Model):
'account.journal',
string='Journal',
required=True)
use_invoice_line_account = fields.Boolean(
string="Invoice account as spread account",
help="Use invoice line's account as Balance sheet / spread account.\n"
"In this case, user need to select expense/revenue account too.")
spread_account_id = fields.Many2one(
'account.account',
string='Spread Balance Sheet Account',
required=True)
required=False)
exp_rev_account_id = fields.Many2one(
'account.account',
string='Expense/Revenue Account',
help="Optional account to overwrite the existing expense/revenue account")
period_number = fields.Integer(
string='Number of Repetitions',
help="Define the number of spread lines")
@ -66,22 +74,28 @@ class AccountSpreadTemplate(models.Model):
if journal:
self.spread_journal_id = journal
def _prepare_spread_from_template(self):
@api.onchange('use_invoice_line_account')
def _onchange_user_invoice_line_account(self):
self.exp_rev_account_id = False
def _prepare_spread_from_template(self, spread_account_id=False):
self.ensure_one()
company = self.company_id
spread_vals = {
'name': self.name,
'template_id': self.id,
'journal_id': self.spread_journal_id.id,
'use_invoice_line_account': self.use_invoice_line_account,
'company_id': company.id,
}
account_id = spread_account_id or self.spread_account_id.id
if self.spread_type == 'sale':
invoice_type = 'out_invoice'
spread_vals['debit_account_id'] = self.spread_account_id.id
spread_vals['debit_account_id'] = account_id
else:
invoice_type = 'in_invoice'
spread_vals['credit_account_id'] = self.spread_account_id.id
spread_vals['credit_account_id'] = account_id
if self.period_number:
spread_vals['period_number'] = self.period_number

View File

@ -1 +1,2 @@
* Andrea Stirpe <a.stirpe@onestein.nl>
* Kitti U. <kittiu@ecosoft.co.th>

View File

@ -1,3 +1,10 @@
12.0.1.1.0
~~~~~~~~~~
* [ENH] Add optional Expense/Revenue Account in Chart Template, which can be used
in place of account from invoice line to set Expense/Revenue account in the spread
12.0.1.0.0
~~~~~~~~~~

View File

@ -69,6 +69,7 @@ Under Invoicing -> Configuration -> Accounting -> Spread Templates, create a new
* *Spread Type*
* *Spread Balance Sheet Account*
* *Expense/Revenue Account* This option visible if invoice line account is balance sheet account, user need to specify this too.
* *Journal*
When creating a new Spread Costs/Revenues Board, select the right template.

View File

@ -37,6 +37,7 @@
<field name="display_recompute_buttons" invisible="1"/>
<field name="display_move_line_auto_post" invisible="1"/>
<field name="all_posted" invisible="1"/>
<field name="use_invoice_line_account" invisible="1"/>
</group>
</group>
<group name="accounts">
@ -46,14 +47,26 @@
attrs="{'invisible':[('invoice_type','not in',('out_invoice','in_refund'))]}"/>
<label for="debit_account_id" colspan="3" string="Expense account"
attrs="{'invisible':[('invoice_type','not in',('in_invoice','out_refund'))]}"/>
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('out_invoice','in_refund'))]}">
The Balance Sheet account used for the spreading.<br/>This account is the counterpart of the account in the invoice line.
</span>
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('in_invoice','out_refund'))]}">
The Expense account in the vendor bill line.<br/>Usually the same account of the vendor bill line.
</span>
<div attrs="{'invisible': [('use_invoice_line_account', '=', True)]}" colspan="2">
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('out_invoice','in_refund'))]}">
The Balance Sheet account used for the spreading.<br/>This account is the counterpart of the account in the invoice line.
</span>
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('in_invoice','out_refund'))]}">
The Expense account in the vendor bill line.<br/>Usually the same account of the vendor bill line.
</span>
</div>
<div attrs="{'invisible': [('use_invoice_line_account', '!=', True)]}" colspan="2">
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('out_invoice','in_refund'))]}">
The Balance Sheet account.<br/>This is the account in the invoice line.
</span>
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('in_invoice','out_refund'))]}">
The Expense account used for the spreading.<br/>This account is the counterpart of the account of the vendor bill line.
</span>
</div>
<field name="debit_account_id" required="1" domain="[('company_id', '=', company_id), ('deprecated', '=', False)]" attrs="{'readonly':[('invoice_line_id','!=',False)]}"/>
<span class="help-block text-danger" colspan="2"
attrs="{'invisible':[('is_debit_account_deprecated','!=',True)]}">
@ -66,14 +79,26 @@
attrs="{'invisible':[('invoice_type','not in',('out_invoice','in_refund'))]}"/>
<label for="credit_account_id" colspan="3" string="Balance sheet account / Spread account"
attrs="{'invisible':[('invoice_type','not in',('in_invoice','out_refund'))]}"/>
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('out_invoice','in_refund'))]}">
The Revenue account in the invoice line.<br/>Usually the same account of the invoice line.
</span>
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('in_invoice','out_refund'))]}">
The Balance Sheet account used for the spreading.<br/>This account is the counterpart of the account in the vendor bill line.
</span>
<div attrs="{'invisible': [('use_invoice_line_account', '=', True)]}" colspan="2">
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('out_invoice','in_refund'))]}">
The Revenue account in the invoice line.<br/>Usually the same account of the invoice line.
</span>
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('in_invoice','out_refund'))]}">
The Balance Sheet account used for the spreading.<br/>This account is the counterpart of the account in the vendor bill line.
</span>
</div>
<div attrs="{'invisible': [('use_invoice_line_account', '!=', True)]}" colspan="2">
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('out_invoice','in_refund'))]}">
The Revenue account used for the spreading.<br/>This account is the counterpart of the account of the invoice line.
</span>
<span class="help-block" colspan="2"
attrs="{'invisible':[('invoice_type','not in',('in_invoice','out_refund'))]}">
The Balance Sheet account.<br/>This is the account in the vendor bill line.
</span>
</div>
<field name="credit_account_id" required="1" domain="[('company_id', '=', company_id), ('deprecated', '=', False)]" attrs="{'readonly':[('invoice_line_id','!=',False)]}"/>
<span class="help-block text-danger" colspan="2"
attrs="{'invisible':[('is_credit_account_deprecated','!=',True)]}">

View File

@ -21,7 +21,10 @@
<field name="start_date"/>
</group>
<group>
<field name="spread_account_id" domain="[('company_id', '=', company_id), ('deprecated', '=', False)]" options="{'no_create': True}"/>
<field name="use_invoice_line_account"/>
<field name="spread_account_id" domain="[('company_id', '=', company_id), ('deprecated', '=', False)]" options="{'no_create': True}"
attrs="{'required': [('use_invoice_line_account', '!=', True)], 'invisible': [('use_invoice_line_account', '=', True)]}" />
<field name="exp_rev_account_id" attrs="{'invisible': ['|', ('use_invoice_line_account', '=', False)], 'required': [('use_invoice_line_account', '=', True)]}" domain="[('company_id', '=', company_id), ('deprecated', '=', False)]" options="{'no_create': True}"/>
<field name="spread_journal_id" domain="[('company_id', '=', company_id)]" widget="selection"/>
</group>
</group>

View File

@ -60,10 +60,18 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
template_id = fields.Many2one(
'account.spread.template',
string='Spread Template')
use_invoice_line_account = fields.Boolean(
string="Use invoice line's account",
help="Use invoice line's account as Balance sheet / spread account.\n"
"In this case, user need to select expense/revenue account too.")
spread_account_id = fields.Many2one(
'account.account',
string='Balance sheet account / Spread account',
store=True)
exp_rev_account_id = fields.Many2one(
'account.account',
string='Expense/revenue account',
help="Optional account to overwrite the existing expense/revenue account")
spread_journal_id = fields.Many2one(
'account.journal',
string='Spread Journal',
@ -108,6 +116,12 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
res = {'domain': {'spread_id': domain}}
return res
@api.onchange('use_invoice_line_account')
def _onchange_user_invoice_line_account(self):
self.spread_account_id = (self.use_invoice_line_account and
self.invoice_line_id.account_id or False)
self.exp_rev_account_id = False
@api.multi
def confirm(self):
self.ensure_one()
@ -129,9 +143,11 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
elif self.spread_action_type == 'new':
debit_account = credit_account = self.spread_account_id
if self.invoice_type in ('out_invoice', 'in_refund'):
credit_account = self.invoice_line_id.account_id
credit_account = (self.exp_rev_account_id or
self.invoice_line_id.account_id)
else:
debit_account = self.invoice_line_id.account_id
debit_account = (self.exp_rev_account_id or
self.invoice_line_id.account_id)
analytic_account = self.invoice_line_id.account_analytic_id
analytic_tags = self.invoice_line_id.analytic_tag_ids
@ -149,6 +165,7 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
'default_name': self.invoice_line_id.name,
'default_invoice_type': self.invoice_type,
'default_invoice_line_id': self.invoice_line_id.id,
'default_use_invoice_line_account': self.use_invoice_line_account,
'default_debit_account_id': debit_account.id,
'default_credit_account_id': credit_account.id,
'default_journal_id': self.spread_journal_id.id,
@ -160,8 +177,14 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
elif self.spread_action_type == 'template':
if not self.invoice_line_id.spread_id:
account = self.invoice_line_id.account_id
spread_vals = self.template_id._prepare_spread_from_template()
spread_account_id = False
if self.template_id.use_invoice_line_account:
account = self.template_id.exp_rev_account_id
spread_account_id = self.invoice_line_id.account_id.id
spread_vals = self.template_id._prepare_spread_from_template(
spread_account_id=spread_account_id
)
date_invoice = self.invoice_id.date_invoice
date_invoice = date_invoice or self.template_id.start_date
date_invoice = date_invoice or fields.Date.today()

View File

@ -17,7 +17,9 @@
<field name="spread_action_type" widget="radio"/>
<field name="spread_id" attrs="{'invisible': [('spread_action_type', '!=', 'link')],'required': [('spread_action_type', '=', 'link')]}" domain="[('invoice_type', '=', invoice_type)]" options="{'no_create': True}"/>
<field name="template_id" attrs="{'invisible': [('spread_action_type', '!=', 'template')],'required': [('spread_action_type', '=', 'template')]}" domain="[('spread_type', '=', spread_type)]" options="{'no_create': True}"/>
<field name="use_invoice_line_account" attrs="{'invisible': [('spread_action_type', '!=', 'new')]}"/>
<field name="spread_account_id" attrs="{'invisible': [('spread_action_type', '!=', 'new')],'required': [('spread_action_type', '=', 'new')]}" domain="[('company_id', '=', company_id), ('deprecated', '=', False)]" options="{'no_create': True}"/>
<field name="exp_rev_account_id" attrs="{'invisible': ['|', ('use_invoice_line_account', '=', False), ('spread_action_type', '!=', 'new')], 'required': [('use_invoice_line_account', '=', True)]}" domain="[('company_id', '=', company_id), ('deprecated', '=', False)]" options="{'no_create': True}"/>
<field name="spread_journal_id" attrs="{'invisible': [('spread_action_type', '!=', 'new')],'required': [('spread_action_type', '=', 'new')]}" domain="[('company_id', '=', company_id)]" options="{'no_create': True}"/>
</group>
</group>