Skip to content

Commit

Permalink
[FIX][account_cash_discount_base] Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpeiffer committed Dec 14, 2015
1 parent 592e7e8 commit e83f681
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
21 changes: 16 additions & 5 deletions account_cash_discount_base/models/account_invoice.py
Expand Up @@ -32,21 +32,29 @@ class account_invoice(models.Model):
.Float(string='Discount Percent', readonly=True,
states={'draft': [('readonly', False)]})
discount_amount = fields\
.Float(string='Amount Discount deducted', compute='_compute_discount_amount')
forced_discount_amount = fields\
.Float(string='Amount Discount deducted', readonly=True,
states={'draft': [('readonly', False)]})
discount = fields\
.Float(compute='_compute_discount', string='Amount Discount',
store=True)
.Float(compute='_compute_discount', string='Amount Discount')
discount_delay = fields\
.Integer(string='Discount Delay (days)', readonly=True,
states={'draft': [('readonly', False)]})
discount_due_date = fields.Date(string='Discount Due Date', readonly=True,
states={'draft': [('readonly', False)]})
discount_due_date_readonly =\
fields.Date(string='Discount Due Date',
compute='_compute_discount_due_date')
force_discount_amount = fields.Boolean(string="Force Discount Amount",
states={'draft': [('readonly',
False)]})

@api.depends('discount_amount')
@api.depends('discount_due_date')
@api.one
def _compute_discount_due_date(self):
self.discount_due_date_readonly = self.discount_due_date

@api.one
def _compute_discount(self):
self.discount = self.amount_total - self.discount_amount
Expand All @@ -63,9 +71,10 @@ def _discount_delay_change(self):
due_date = date_invoice + timedelta(days=self.discount_delay)
self.discount_due_date = due_date.date()

@api.onchange('discount_percent', 'amount_tax', 'amount_total')
@api.depends('discount_percent', 'amount_tax', 'amount_total',
'force_discount_amount', 'forced_discount_amount')
@api.one
def _change_discount_amount(self):
def _compute_discount_amount(self):
if not self.force_discount_amount:
discount_amount = 0.0
if self.discount_percent == 0.0:
Expand All @@ -75,6 +84,8 @@ def _change_discount_amount(self):
(0.0 + self.discount_percent/100)
discount_amount = (self.amount_total - discount)
self.discount_amount = discount_amount
else:
self.discount_amount = self.forced_discount_amount

@api.multi
def action_move_create(self):
Expand Down
11 changes: 7 additions & 4 deletions account_cash_discount_base/views/account_invoice_view.xml
Expand Up @@ -9,12 +9,14 @@
<xpath expr="//field[@name='residual']" position="before">
<field name="discount_percent" />
<field name="force_discount_amount" />
<field name="discount_amount" />
<field name="forced_discount_amount" attrs="{'invisible': [('force_discount_amount', '=', False)]}"/>
<field name="discount_amount" attrs="{'invisible': [('force_discount_amount', '=', True)]}"/>
<field name="discount" />
</xpath>
<xpath expr="//field[@name='date_due']" position="after">
<field name="discount_delay" />
<field name="discount_due_date" attrs="{'readonly': ['|', ('discount_delay', '!=', 0), ('state', '!=', 'draft')]}" />
<field name="discount_due_date" attrs="{'invisible': [('discount_delay', '!=', 0)]}" />
<field name="discount_due_date_readonly" attrs="{'invisible': [('discount_delay', '=', 0)]}" />
</xpath>
</field>
</record>
Expand All @@ -25,12 +27,13 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='residual']" position="before">
<field name="discount_percent" />
<field name="discount_amount" readonly="1"/>
<field name="discount_amount" />
<field name="discount" />
</xpath>
<xpath expr="//field[@name='date_due']" position="after">
<field name="discount_delay" />
<field name="discount_due_date" readonly="1"/>
<field name="discount_due_date" invisible="1" />
<field name="discount_due_date_readonly"/>
</xpath>
</field>
</record>
Expand Down

0 comments on commit e83f681

Please sign in to comment.