[IMP] Give reference of discount method in Credit Notes and add blank div in customer invoice form

This commit is contained in:
Haresh Chavda 2018-06-14 11:51:27 +05:30
parent 9c9cc927dd
commit 4199b5d3f1
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,16 +9,17 @@ 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)
total_discount += \ total_discount += \
(total_price * invoice_line_id.discount) / 100 (total_price * invoice_line_id.discount) / 100
record.discount = record.currency_id.round(total_discount) record.discount = record.currency_id.round(total_discount)
@api.multi @api.multi
@api.depends('invoice_line_ids', 'discount_per', 'discount_amount') @api.depends('invoice_line_ids', 'discount_per', 'discount_amount')
@ -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,8 +81,9 @@ class AccountInvoice(models.Model):
@api.onchange('discount_method') @api.onchange('discount_method')
def onchange_discount_method(self): def onchange_discount_method(self):
self.discount_amount = 0.0 if not self.refund_invoice_id:
self.discount_per = 0.0 self.discount_amount = 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:
raise Warning('No Invoice Line(s) were found!') raise Warning('No Invoice Line(s) were found!')

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">