mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Code review
This commit is contained in:
@@ -58,16 +58,16 @@ class AccountSpread(models.Model):
|
||||
compute='_compute_deprecated_accounts')
|
||||
unspread_amount = fields.Float(
|
||||
digits=dp.get_precision('Account'),
|
||||
compute='_compute_spread_amount')
|
||||
compute='_compute_amounts')
|
||||
unposted_amount = fields.Float(
|
||||
digits=dp.get_precision('Account'),
|
||||
compute='_compute_spread_amount')
|
||||
compute='_compute_amounts')
|
||||
posted_amount = fields.Float(
|
||||
digits=dp.get_precision('Account'),
|
||||
compute='_compute_spread_amount')
|
||||
compute='_compute_amounts')
|
||||
total_amount = fields.Float(
|
||||
digits=dp.get_precision('Account'),
|
||||
compute='_compute_spread_amount')
|
||||
compute='_compute_amounts')
|
||||
line_ids = fields.One2many(
|
||||
'account.spread.line',
|
||||
'spread_id',
|
||||
@@ -88,8 +88,8 @@ class AccountSpread(models.Model):
|
||||
invoice_line_id = fields.Many2one(
|
||||
'account.invoice.line',
|
||||
string='Invoice line',
|
||||
compute='_compute_invoice',
|
||||
inverse='_inverse_invoice',
|
||||
compute='_compute_invoice_line',
|
||||
inverse='_inverse_invoice_line',
|
||||
store=True)
|
||||
invoice_id = fields.Many2one(
|
||||
related='invoice_line_id.invoice_id',
|
||||
@@ -124,8 +124,8 @@ class AccountSpread(models.Model):
|
||||
company_id = res['company_id']
|
||||
default_journal = self.env['account.journal'].search([
|
||||
('type', '=', 'general'),
|
||||
('company_id', '=', company_id)],
|
||||
limit=1)
|
||||
('company_id', '=', company_id)
|
||||
], limit=1)
|
||||
if 'journal_id' not in res and default_journal:
|
||||
res['journal_id'] = default_journal.id
|
||||
return res
|
||||
@@ -139,14 +139,14 @@ class AccountSpread(models.Model):
|
||||
spread.spread_type = 'purchase'
|
||||
|
||||
@api.depends('invoice_line_ids', 'invoice_line_ids.invoice_id')
|
||||
def _compute_invoice(self):
|
||||
def _compute_invoice_line(self):
|
||||
for spread in self:
|
||||
invoice_lines = spread.invoice_line_ids
|
||||
line = invoice_lines and invoice_lines[0] or False
|
||||
spread.invoice_line_id = line
|
||||
|
||||
@api.multi
|
||||
def _inverse_invoice(self):
|
||||
def _inverse_invoice_line(self):
|
||||
for spread in self:
|
||||
invoice_line = spread.invoice_line_id
|
||||
spread.write({
|
||||
@@ -154,7 +154,7 @@ class AccountSpread(models.Model):
|
||||
})
|
||||
|
||||
@api.multi
|
||||
def _compute_spread_amount(self):
|
||||
def _compute_amounts(self):
|
||||
for spread in self:
|
||||
moves_amount = 0.0
|
||||
posted_amount = 0.0
|
||||
@@ -249,7 +249,7 @@ class AccountSpread(models.Model):
|
||||
return 1
|
||||
|
||||
@api.multi
|
||||
def _init_spread_line_date(self, posted_line_ids):
|
||||
def _init_line_date(self, posted_line_ids):
|
||||
"""Calculates the initial spread date. This method
|
||||
is used by "def _compute_spread_board()" method.
|
||||
"""
|
||||
@@ -265,22 +265,18 @@ class AccountSpread(models.Model):
|
||||
return spread_date
|
||||
|
||||
@api.multi
|
||||
def _next_line_date(self, month_day, spread_date):
|
||||
def _next_line_date(self, month_day, date):
|
||||
"""Calculates the next spread date. This method
|
||||
is used by "def _compute_spread_board()" method.
|
||||
"""
|
||||
self.ensure_one()
|
||||
months = self._compute_spread_period_duration()
|
||||
spread_date = spread_date + relativedelta(months=months)
|
||||
date = date + relativedelta(months=months)
|
||||
# get the last day of the month
|
||||
if month_day > 28:
|
||||
max_day_in_month = calendar.monthrange(
|
||||
spread_date.year, spread_date.month
|
||||
)[1]
|
||||
spread_date = spread_date.replace(
|
||||
day=min(max_day_in_month, month_day)
|
||||
)
|
||||
return spread_date
|
||||
max_day_in_month = calendar.monthrange(date.year, date.month)[1]
|
||||
date = date.replace(day=min(max_day_in_month, month_day))
|
||||
return date
|
||||
|
||||
@api.multi
|
||||
def _compute_spread_board(self):
|
||||
@@ -302,7 +298,7 @@ class AccountSpread(models.Model):
|
||||
if self.unposted_amount != 0.0:
|
||||
unposted_amount = self.unposted_amount
|
||||
|
||||
spread_date = self._init_spread_line_date(posted_line_ids)
|
||||
spread_date = self._init_line_date(posted_line_ids)
|
||||
|
||||
month_day = spread_date.day
|
||||
number_of_periods = self._get_number_of_periods(month_day)
|
||||
@@ -343,13 +339,11 @@ class AccountSpread(models.Model):
|
||||
return fields.Date.to_string(spread_date + relativedelta(day=31))
|
||||
|
||||
@api.multi
|
||||
def _compute_board_amount(self, sequence, unposted_amount,
|
||||
undone_dotation_number):
|
||||
def _compute_board_amount(self, sequence, amount, number_of_periods):
|
||||
"""Calculates the amount for the spread lines."""
|
||||
self.ensure_one()
|
||||
amount = unposted_amount
|
||||
amount_to_spread = self.total_amount
|
||||
if sequence != undone_dotation_number:
|
||||
if sequence != number_of_periods:
|
||||
amount = amount_to_spread / self.period_number
|
||||
if sequence == 1:
|
||||
date = fields.Datetime.from_string(self.spread_date)
|
||||
|
||||
@@ -15,9 +15,9 @@ class AccountInvoiceSpreadLine(models.Model):
|
||||
amount = fields.Float(digits=dp.get_precision('Account'), required=True)
|
||||
date = fields.Date(required=True)
|
||||
spread_id = fields.Many2one(
|
||||
'account.spread', string='Spread', ondelete='cascade')
|
||||
'account.spread', string='Spread Board', ondelete='cascade')
|
||||
move_id = fields.Many2one(
|
||||
'account.move', string='Spread Entry', readonly=True)
|
||||
'account.move', string='Journal Entry', readonly=True)
|
||||
|
||||
@api.multi
|
||||
def create_and_reconcile_moves(self):
|
||||
|
||||
5
account_spread_cost_revenue/readme/HISTORY.rst
Normal file
5
account_spread_cost_revenue/readme/HISTORY.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
11.0.1.0.0
|
||||
~~~~~~~~~~
|
||||
|
||||
* [ADD] Module account_spread_cost_revenue.
|
||||
(`#715 <https://github.com/OCA/account-financial-tools/pull/715>`_)
|
||||
@@ -1 +1,2 @@
|
||||
* Verify last day of month
|
||||
* Add help in fields definition
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_account_spread_cost_revenue_full,Full access on account.spread,model_account_spread,account.group_account_manager,1,1,1,1
|
||||
access_account_spread_cost_revenue_read,Read access on account.spread,model_account_spread,base.group_user,1,0,0,0
|
||||
access_account_spread_cost_revenue_read,Read access on account.spread,model_account_spread,account.group_account_user,1,0,0,0
|
||||
access_account_spread_cost_revenue_line_full,Full access on account.spread.line,model_account_spread_line,account.group_account_manager,1,1,1,1
|
||||
access_account_spread_cost_revenue_line_read,Read access on account.spread.line,model_account_spread_line,account.group_account_user,1,0,0,0
|
||||
access_account_spread_cost_revenue_template_full,Full access on account.spread.template,model_account_spread_template,account.group_account_manager,1,1,1,1
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
<field name="inherit_id" ref="account.invoice_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='quantity']" position="before">
|
||||
<field name="spread_check" widget="spread_line_widget"/>
|
||||
<field name="spread_check" widget="spread_line_widget" groups="account.group_account_user,account.group_account_manager"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
@@ -16,7 +16,7 @@
|
||||
<field name="inherit_id" ref="account.invoice_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='quantity']" position="before">
|
||||
<field name="spread_check" widget="spread_line_widget"/>
|
||||
<field name="spread_check" widget="spread_line_widget" groups="account.group_account_user,account.group_account_manager"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
<form>
|
||||
<header>
|
||||
<button name="compute_spread_board" type="object" string="Recalculate unposted lines" class="oe_highlight" attrs="{'invisible': [('debit_account_id', '=', False)]}" />
|
||||
<button name="action_recalculate_spread" type="object" string="Recalculate entire spread" attrs="{'invisible': [('debit_account_id', '=', False)]}" groups="account.group_account_user" />
|
||||
<button name="action_undo_spread" type="object" string="Undo spread" attrs="{'invisible': [('line_ids', '=', [])]}" groups="account.group_account_user" />
|
||||
<button name="action_unlink_invoice_line" type="object" string="Unlink Invoice Line" attrs="{'invisible': [('invoice_line_id', '=', False)]}" groups="account.group_account_user" />
|
||||
<button name="action_recalculate_spread" type="object" string="Recalculate entire spread" attrs="{'invisible': [('debit_account_id', '=', False)]}" groups="account.group_account_manager" />
|
||||
<button name="action_undo_spread" type="object" string="Undo spread" attrs="{'invisible': [('line_ids', '=', [])]}" groups="account.group_account_manager" />
|
||||
<button name="action_unlink_invoice_line" type="object" string="Unlink Invoice Line" attrs="{'invisible': [('invoice_line_id', '=', False)]}" groups="account.group_account_manager" />
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_button_box">
|
||||
@@ -95,11 +95,11 @@
|
||||
<field name="amount" attrs="{'readonly':[('move_id','!=',False)]}" sum="Total"/>
|
||||
<field name="date" readonly="1"/>
|
||||
<field name="move_id" readonly="1"/>
|
||||
<button name="create_move" icon="fa fa-play" string="Create Move" type="object" groups="account.group_account_user"
|
||||
<button name="create_move" icon="fa fa-play" string="Create Move" type="object" groups="account.group_account_manager"
|
||||
attrs="{'invisible':['|',('move_id','!=',False)]}"/>
|
||||
<button name="open_move" icon="fa fa-plus-square-o" string="View Move" type="object"
|
||||
attrs="{'invisible':[('move_id','=',False)]}"/>
|
||||
<button name="unlink_move" icon="fa fa-times" string="Delete Move" type="object" confirm="This will delete the move. Are you sure ?" groups="account.group_account_user"
|
||||
<button name="unlink_move" icon="fa fa-times" string="Delete Move" type="object" confirm="This will delete the move. Are you sure ?" groups="account.group_account_manager"
|
||||
attrs="{'invisible':[('move_id','=',False)]}"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
@@ -50,6 +50,6 @@
|
||||
<menuitem id="menu_action_account_spread_template_form"
|
||||
parent="account.account_account_menu"
|
||||
action="action_account_spread_template_form"
|
||||
groups="account.group_account_user"/>
|
||||
groups="account.group_account_manager"/>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<field name="inherit_id" ref="base.view_company_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//notebook">
|
||||
<page name="account_spread_cost_revenue" string="Account Spread" groups="account.group_account_user">
|
||||
<page name="account_spread_cost_revenue" string="Account Spread" groups="account.group_account_manager">
|
||||
<group>
|
||||
<group string="Default Spread Accounts">
|
||||
<field name="default_spread_revenue_account_id" />
|
||||
|
||||
Reference in New Issue
Block a user