Merge branch 'master-account-discount' into 'master'

Discount method in Credit Notes and add blank div in customer invoice form.

See merge request flectra-hq/flectra!76
This commit is contained in:
Parthiv Patel 2018-06-18 06:01:22 +00:00
commit 921d871a52
3 changed files with 27 additions and 9 deletions

View File

@ -226,6 +226,8 @@
</div> </div>
<field name="has_outstanding" invisible="1"/> <field name="has_outstanding" invisible="1"/>
<sheet string="Vendor Bill"> <sheet string="Vendor Bill">
<div class="oe_button_box" name="button_box">
</div>
<div> <div>
<label string="Draft Bill" attrs="{'invisible': ['|',('state','!=','draft'), ('type','!=','in_invoice')]}"/> <label string="Draft Bill" attrs="{'invisible': ['|',('state','!=','draft'), ('type','!=','in_invoice')]}"/>
<label string="- First Number:" attrs="{'invisible': [('sequence_number_next_prefix','=',False)]}"/> <label string="- First Number:" attrs="{'invisible': [('sequence_number_next_prefix','=',False)]}"/>

View File

@ -9,10 +9,11 @@ class AccountInvoice(models.Model):
_inherit = "account.invoice" _inherit = "account.invoice"
@api.multi @api.multi
@api.depends('discount_amount', 'discount_per', 'amount_untaxed') @api.depends('discount_amount', 'discount_per', 'amount_untaxed',
'invoice_line_ids')
def _get_discount(self): def _get_discount(self):
total_discount = 0.0
for record in self: for record in self:
total_discount = 0.0
for invoice_line_id in record.invoice_line_ids: for invoice_line_id in record.invoice_line_ids:
total_price = ( total_price = (
invoice_line_id.quantity * invoice_line_id.price_unit) invoice_line_id.quantity * invoice_line_id.price_unit)
@ -40,7 +41,6 @@ class AccountInvoice(models.Model):
@api.multi @api.multi
def calculate_discount(self): def calculate_discount(self):
self._check_constrains()
for line in self.invoice_line_ids: for line in self.invoice_line_ids:
line.write({'discount': 0.0}) line.write({'discount': 0.0})
# amount_untaxed = self.amount_untaxed # amount_untaxed = self.amount_untaxed
@ -58,6 +58,21 @@ class AccountInvoice(models.Model):
(discount_value_ratio * 100) / line.price_subtotal (discount_value_ratio * 100) / line.price_subtotal
line.write({'discount': discount_per_ratio}) line.write({'discount': discount_per_ratio})
self._onchange_invoice_line_ids() self._onchange_invoice_line_ids()
self._check_constrains()
@api.multi
@api.returns('self')
def refund(self, date_invoice=None,
date=None, description=None, journal_id=None):
result = super(AccountInvoice, self).refund(
date_invoice=date_invoice, date=date,
description=description, journal_id=journal_id)
result.write({
'discount_method': result.refund_invoice_id.discount_method,
'discount_amount': result.refund_invoice_id.discount_amount,
'discount_per': result.refund_invoice_id.discount_per})
result.calculate_discount()
return result
@api.constrains('discount_per', 'discount_amount', 'invoice_line_ids') @api.constrains('discount_per', 'discount_amount', 'invoice_line_ids')
def _check_constrains(self): def _check_constrains(self):
@ -66,6 +81,7 @@ class AccountInvoice(models.Model):
@api.onchange('discount_method') @api.onchange('discount_method')
def onchange_discount_method(self): def onchange_discount_method(self):
if not self.refund_invoice_id:
self.discount_amount = 0.0 self.discount_amount = 0.0
self.discount_per = 0.0 self.discount_per = 0.0
if self.discount_method and not self.invoice_line_ids: if self.discount_method and not self.invoice_line_ids:

View File

@ -9,9 +9,9 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//group[@name='left_panel']" position="inside"> <xpath expr="//group[@name='left_panel']" position="inside">
<separator string="Discount"/> <separator string="Discount"/>
<field name="discount_method" attrs="{'readonly': ['|', ('origin', '!=', False), ('state', '!=', 'draft')]}"/> <field name="discount_method" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="discount_amount" attrs="{'readonly': ['|', '|', ('origin', '!=', False), ('state', '!=', 'draft'), ('discount_method', '=', False)], 'invisible': [('discount_method', '=', 'per')]}"/> <field name="discount_amount" attrs="{'readonly': [('state', '!=', 'draft'), ('discount_method', '=', False)], 'invisible': [('discount_method', '=', 'per')]}"/>
<field name="discount_per" attrs="{'invisible': ['|', ('discount_method', '=', 'fixed'), ('discount_method', '=', False)], 'readonly': ['|', ('origin', '!=', False), ('state', '!=', 'draft')]}"/> <field name="discount_per" attrs="{'invisible': ['|', ('discount_method', '=', 'fixed'), ('discount_method', '=', False)], 'readonly': [('state', '!=', 'draft')]}"/>
<button name="calculate_discount" type="object" class="oe_edit_only oe_link" string="(Update Discount)" attrs="{'invisible': [('discount_method', '=', False)]}" confirm="If you want to apply global discount other discount methods will be reset."/> <button name="calculate_discount" type="object" class="oe_edit_only oe_link" string="(Update Discount)" attrs="{'invisible': [('discount_method', '=', False)]}" confirm="If you want to apply global discount other discount methods will be reset."/>
</xpath> </xpath>
<xpath expr="//field[@name='amount_untaxed']" position="before"> <xpath expr="//field[@name='amount_untaxed']" position="before">