[IMP] account: payment terms usability

* Replace payment term lines options 'last_day_following_month' and 'last_day_current_month' by two new less specific ones allowing choosing the day directly, and thus not limited to the last one anymore (semantically different).
* Rename payment term line option value 'fix_day_following_month' into 'after_invoice_month' for more clarity (no semantic change).

Was task 24239. Was PR #15487
This commit is contained in:
Olivier Colson
2017-11-30 16:08:30 +01:00
committed by qdp-odoo
parent f38ace8de2
commit cd5ce3c7dc
3 changed files with 51 additions and 30 deletions
+6 -6
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- TAGS FOR RETRIEVING THE DEMO ACCOUNTS -->
<record id="demo_capital_account" model="account.account.tag">
@@ -20,22 +20,22 @@
<field name="name">Demo Coffe Machine Account</field>
</record>
<!-- Payment Terms -->
<record id="account_payment_term" model="account.payment.term">
<field name="name">End of Following Month</field>
<field name="note">Payment terms: End of Following Month</field>
<field name="line_ids" eval="[(5, 0), (0, 0, {'value': 'balance', 'value_amount': 0.0, 'sequence': 500, 'days': 0, 'option': 'last_day_following_month'})]"/>
<field name="line_ids" eval="[(5, 0), (0, 0, {'value': 'balance', 'value_amount': 0.0, 'sequence': 500, 'days': 31, 'option': 'day_following_month'})]"/>
</record>
<record id="account_payment_term_advance" model="account.payment.term">
<field name="name">30% Advance End of Following Month</field>
<field name="note">Payment terms: 30% Advance End of Following Month</field>
<field name="line_ids" eval="[(5, 0), (0, 0, {'value': 'percent', 'value_amount': 30.0, 'sequence': 400, 'days': 0, 'option': 'day_after_invoice_date'}),
(0, 0, {'value': 'balance', 'value_amount': 0.0, 'sequence': 500, 'days': 0, 'option': 'last_day_following_month'})]"/>
<field name="line_ids" eval="[(5, 0), (0, 0, {'value': 'percent', 'value_amount': 30.0, 'sequence': 400, 'days': 0, 'option': 'day_after_invoice_date'}),
(0, 0, {'value': 'balance', 'value_amount': 0.0, 'sequence': 500, 'days': 31, 'option': 'day_following_month'})]"/>
</record>
<record id="base.user_demo" model="res.users">
<field name="groups_id" eval="[(4,ref('account.group_account_invoice'))]"/>
<field name="groups_id" eval="[(4,ref('account.group_account_invoice'))]"/>
</record>
<!-- Add Payment terms on some demo partners -->
+21 -10
View File
@@ -1752,13 +1752,16 @@ class AccountPaymentTerm(models.Model):
next_date = fields.Date.from_string(date_ref)
if line.option == 'day_after_invoice_date':
next_date += relativedelta(days=line.days)
elif line.option == 'fix_day_following_month':
if line.day_of_the_month > 0:
months_delta = (line.day_of_the_month < next_date.day) and 1 or 0
next_date += relativedelta(day=line.day_of_the_month, months=months_delta)
elif line.option == 'after_invoice_month':
next_first_date = next_date + relativedelta(day=1, months=1) # Getting 1st of next month
next_date = next_first_date + relativedelta(days=line.days - 1)
elif line.option == 'last_day_following_month':
next_date += relativedelta(day=31, months=1) # Getting last day of next month
elif line.option == 'last_day_current_month':
next_date += relativedelta(day=31, months=0) # Getting last day of next month
elif line.option == 'day_following_month':
next_date += relativedelta(day=line.days, months=1)
elif line.option == 'day_current_month':
next_date += relativedelta(day=line.days, months=0)
result.append((fields.Date.to_string(next_date), amt))
amount -= amt
amount = sum(amt for _, amt in result)
@@ -1788,11 +1791,12 @@ class AccountPaymentTermLine(models.Model):
help="Select here the kind of valuation related to this payment terms line.")
value_amount = fields.Float(string='Value', digits=dp.get_precision('Payment Terms'), help="For percent enter a ratio between 0-100.")
days = fields.Integer(string='Number of Days', required=True, default=0)
day_of_the_month = fields.Integer(string='Day of the month', help="Day of the month on which the invoice must come to its term. If zero or negative, this value will be ignored, and no specific day will be set. If greater than the last day of a month, this number will instead select the last day of this month.")
option = fields.Selection([
('day_after_invoice_date', 'Day(s) after the invoice date'),
('fix_day_following_month', 'Day(s) after the end of the invoice month (Net EOM)'),
('last_day_following_month', 'Last day of following month'),
('last_day_current_month', 'Last day of current month'),
('day_after_invoice_date', "day(s) after the invoice date"),
('after_invoice_month', "day(s) after the end of the invoice month"),
('day_following_month', "of the following month"),
('day_current_month', "of the current month"),
],
default='day_after_invoice_date', required=True, string='Options'
)
@@ -1805,7 +1809,14 @@ class AccountPaymentTermLine(models.Model):
if self.value == 'percent' and (self.value_amount < 0.0 or self.value_amount > 100.0):
raise ValidationError(_('Percentages for Payment Terms Line must be between 0 and 100.'))
@api.constrains('days')
def _check_days(self):
if self.option in ('day_following_month', 'day_current_month') and self.days <= 0:
raise ValidationError(_("The day of the month used for this term must be stricly positive."))
elif self.days < 0:
raise ValidationError(_("The number of days used for a payment term cannot be negative."))
@api.onchange('option')
def _onchange_option(self):
if self.option in ('last_day_current_month', 'last_day_following_month'):
if self.option in ('day_current_month', 'day_following_month'):
self.days = 0
+24 -14
View File
@@ -1600,6 +1600,7 @@
<field name="value_amount" attrs="{'readonly':[('value','=','balance')]}"/>
<field name="days"/>
<field name="option" string=""/>
<field name="day_of_the_month" string="Day of the month"/>
</tree>
</field>
</record>
@@ -1608,27 +1609,36 @@
<field name="model">account.payment.term.line</field>
<field name="arch" type="xml">
<form string="Payment Terms">
<h2>Term Type</h2>
<group>
<group string="Term Type">
<group>
<field name="value" widget="radio"/>
<label for="value_amount" attrs="{'invisible':[('value','=', 'balance')]}"/>
<div attrs="{'invisible':[('value','=', 'balance')]}">
</group>
<group>
<div attrs="{'invisible':[('value','=', 'balance')]}" class="o_row">
<label for="value_amount" attrs="{'invisible':[('value','=', 'balance')]}"/>
<field name="value_amount" class="oe_inline"/>
<label string="%" class="oe_inline" attrs="{'invisible':[('value','!=','percent')]}"/>
</div>
<field name="sequence" invisible="1"/>
</group>
<group string="Due Date Computation">
<label for="days"/>
<div>
<field name="option" widget="radio"/>
<div class="o_row" attrs="{'invisible': [('option', 'in', ['last_day_following_month', 'last_day_current_month'])]}">
<field name="days"/>
days
</div>
</div>
</group>
</group>
<field name="sequence" invisible="1"/>
<h2>Due Date Computation</h2>
<div colspan="2">
<label for="days" string="Due" attrs="{'invisible': [('option','not in',('day_after_invoice_date','after_invoice_month'))]}"/>
<label for="days" string="Due the" attrs="{'invisible': [('option','in',('day_after_invoice_date','after_invoice_month'))]}"/>
<field name="days" class="oe_inline"/>
<label for="option" string=""/> <!--Empty label to force space between elements-->
<field name="option" class="oe_inline"/>
</div>
<div colspan="2" attrs="{'invisible': [('option','!=', 'day_after_invoice_date')]}">
<label for="day_of_the_month" string="On the"/>
<field name="day_of_the_month" class="oe_inline"/>
<label string="of the month"/>
</div>
</form>
</field>
</record>