From 9dde9ff29d5426ce389bcc8b32d14ee9eeda7f5b Mon Sep 17 00:00:00 2001 From: Parth Choksi Date: Mon, 15 Jul 2019 07:27:08 +0000 Subject: [PATCH] [IMP] sale: added currency field for fixed amount in invoice While creating the invoice order, if you choose the radio button of Down Payment(Fixed amount) then the field with currency will be shown and if you choose the Down Payment(Percentage) then the field with percentage symbol will be shown and evaluated respectively. task-2033229 --- addons/sale/tests/test_sale_to_invoice.py | 2 +- addons/sale/wizard/sale_make_invoice_advance.py | 16 ++++++++++++---- .../wizard/sale_make_invoice_advance_views.xml | 5 ++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/addons/sale/tests/test_sale_to_invoice.py b/addons/sale/tests/test_sale_to_invoice.py index 97386c83b66..5a2458caf1e 100644 --- a/addons/sale/tests/test_sale_to_invoice.py +++ b/addons/sale/tests/test_sale_to_invoice.py @@ -78,7 +78,7 @@ class TestSaleToInvoice(TestCommonSaleNoChart): # Let's do an invoice for a deposit of 100 payment = self.env['sale.advance.payment.inv'].with_context(self.context).create({ 'advance_payment_method': 'fixed', - 'amount': 100, + 'fixed_amount': 100, 'deposit_account_id': self.account_income.id }) payment.create_invoices() diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py index 73d5e0b63d7..f7ad90721ed 100644 --- a/addons/sale/wizard/sale_make_invoice_advance.py +++ b/addons/sale/wizard/sale_make_invoice_advance.py @@ -38,6 +38,12 @@ class SaleAdvancePaymentInv(models.TransientModel): return False + @api.model + def _default_currency_id(self): + if self._context.get('active_model') == 'sale.order' and self._context.get('active_id', False): + sale_order = self.env['sale.order'].browse(self._context.get('active_id')) + return sale_order.currency_id + advance_payment_method = fields.Selection([ ('delivered', 'Regular invoice'), ('percentage', 'Down payment (percentage)'), @@ -50,7 +56,9 @@ class SaleAdvancePaymentInv(models.TransientModel): product_id = fields.Many2one('product.product', string='Down Payment Product', domain=[('type', '=', 'service')], default=_default_product_id) count = fields.Integer(default=_count, string='Order Count') - amount = fields.Float('Down Payment Amount', digits='Account', help="The amount to be invoiced in advance, taxes excluded.") + amount = fields.Float('Down Payment Amount', digits='Account', help="The percentage of amount to be invoiced in advance, taxes excluded.") + currency_id = fields.Many2one('res.currency', string='Currency', default=_default_currency_id) + fixed_amount = fields.Monetary('Down Payment Amount(Fixed)', digits='Account', help="The fixed amount to be invoiced in advance, taxes excluded.") deposit_account_id = fields.Many2one("account.account", string="Income Account", domain=[('deprecated', '=', False)], help="Account used for deposits", default=_default_deposit_account_id) deposit_taxes_id = fields.Many2many("account.tax", string="Customer Taxes", help="Taxes used for deposits", default=_default_deposit_taxes_id) @@ -62,13 +70,13 @@ class SaleAdvancePaymentInv(models.TransientModel): return {} def _create_invoice(self, order, so_line, amount): - if self.amount <= 0.00: + if (self.advance_payment_method == 'percentage' and self.amount <= 0.00) or (self.advance_payment_method == 'fixed' and self.fixed_amount <= 0.00): raise UserError(_('The value of the down payment amount must be positive.')) if self.advance_payment_method == 'percentage': amount = order.amount_untaxed * self.amount / 100 name = _("Down payment of %s%%") % (self.amount,) else: - amount = self.amount + amount = self.fixed_amount name = _('Down Payment') invoice_vals = { @@ -121,7 +129,7 @@ class SaleAdvancePaymentInv(models.TransientModel): if self.advance_payment_method == 'percentage': amount = order.amount_untaxed * self.amount / 100 else: - amount = self.amount + amount = self.fixed_amount if self.product_id.invoice_policy != 'order': raise UserError(_('The product used to invoice a down payment should have an invoice policy set to "Ordered quantities". Please update your deposit product to be able to create a deposit invoice.')) if self.product_id.type != 'service': diff --git a/addons/sale/wizard/sale_make_invoice_advance_views.xml b/addons/sale/wizard/sale_make_invoice_advance_views.xml index c2b6a1e2445..03e7ebbff4d 100644 --- a/addons/sale/wizard/sale_make_invoice_advance_views.xml +++ b/addons/sale/wizard/sale_make_invoice_advance_views.xml @@ -24,8 +24,11 @@ invisible="1"/>