diff --git a/addons/account_discount/__init__.py b/addons/account_discount/__init__.py new file mode 100644 index 00000000..84245eb2 --- /dev/null +++ b/addons/account_discount/__init__.py @@ -0,0 +1,3 @@ +# Part of Flectra See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/addons/account_discount/__manifest__.py b/addons/account_discount/__manifest__.py new file mode 100644 index 00000000..ef858027 --- /dev/null +++ b/addons/account_discount/__manifest__.py @@ -0,0 +1,28 @@ +# Part of Flectra See LICENSE file for full copyright and licensing details. + +{ + 'name': "Account Discount", + 'description': """ + Customized module for amending discounts + """, + 'summary': 'Global Discount on Account Invoice', + 'author': 'FlectraHQ', + 'category': 'Accounting', + 'website': 'https://flectrahq.com', + 'version': '1.0', + 'depends': ['account_invoicing'], + 'data': [ + 'security/ir.model.access.csv', + 'data/account_discount_data.xml', + 'views/account_invoice_views.xml', + 'views/res_config_settings_views.xml', + 'views/discount_config_view.xml', + 'report/report_menu.xml', + 'report/custom_invoice_report.xml', + ], + 'demo':[ + 'demo/discount_config_demo.xml', + ], + 'installable': True, + 'auto_install': False, +} diff --git a/addons/account_discount/data/account_discount_data.xml b/addons/account_discount/data/account_discount_data.xml new file mode 100644 index 00000000..04e2310c --- /dev/null +++ b/addons/account_discount/data/account_discount_data.xml @@ -0,0 +1,22 @@ + + + + + + 1000 + 25 + + + + + 500 + 15 + + + + + 100 + 10 + + + diff --git a/addons/account_discount/demo/discount_config_demo.xml b/addons/account_discount/demo/discount_config_demo.xml new file mode 100644 index 00000000..1a8b6fca --- /dev/null +++ b/addons/account_discount/demo/discount_config_demo.xml @@ -0,0 +1,15 @@ + + + + + + 1200 + 10 + + + + + 2500 + 25 + + \ No newline at end of file diff --git a/addons/account_discount/i18n/account_discount.pot b/addons/account_discount/i18n/account_discount.pot new file mode 100644 index 00000000..d9b7d5f7 --- /dev/null +++ b/addons/account_discount/i18n/account_discount.pot @@ -0,0 +1,252 @@ +# Translation of Flectra Server. +# This file contains the translation of the following modules: +# * account_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Flectra Server 1.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-04 11:43+0000\n" +"PO-Revision-Date: 2018-01-04 11:43+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_discount +#: model:ir.ui.view,arch_db:account_discount.custom_invoice_report_layout +msgid "&nbsp;on" +msgstr "" + +#. module: account_discount +#: model:ir.ui.view,arch_db:account_discount.inherit_account_invoice_form +msgid "(Update Discount)" +msgstr "" + +#. module: account_discount +#: model:ir.ui.view,arch_db:account_discount.custom_invoice_report_layout +msgid "Discount" +msgstr "" + +#. module: account_discount +#: model:ir.ui.view,arch_db:account_discount.custom_invoice_report_layout +msgid "Gross Amount" +msgstr "" + +#. module: account_discount +#: model:ir.ui.view,arch_db:account_discount.custom_invoice_report_layout +msgid "Subtotal" +msgstr "" + +#. module: account_discount +#: model:ir.ui.view,arch_db:account_discount.custom_invoice_report_layout +msgid "Total" +msgstr "" + +#. module: account_discount +#: model:ir.ui.view,arch_db:account_discount.account_discount_config_view_form +msgid "Account Discount Configuration" +msgstr "" + +#. module: account_discount +#: model:ir.ui.view,arch_db:account_discount.res_config_settings_view_form_invoice_discount_form +msgid "Allow global discount on the Invoice" +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/discount_config.py:21 +#, python-format +msgid "Assigned group already exist!" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_discount_config_create_uid +msgid "Created by" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_discount_config_create_date +msgid "Created on" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_invoice_discount +#: model:ir.ui.view,arch_db:account_discount.inherit_account_invoice_form +msgid "Discount" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_invoice_discount_per +msgid "Discount (%)" +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/account_invoice.py:123 +#, python-format +msgid "Discount (%s) should be less than Gross Amount (%s)." +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_invoice_discount_amount +msgid "Discount Amount" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_invoice_discount_method +msgid "Discount Method" +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/account_invoice.py:121 +#, python-format +msgid "Discount should be less than Gross Amount" +msgstr "" + +#. module: account_discount +#: model:ir.actions.act_window,name:account_discount.action_account_discount_config +#: model:ir.ui.menu,name:account_discount.menu_account_order +msgid "Discounts" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_discount_config_display_name +msgid "Display Name" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_res_config_settings_global_discount_invoice_apply +msgid "Do you want to set global discount limit?" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_discount_config_fix_amount +#: model:ir.model.fields,field_description:account_discount.field_res_config_settings_global_discount_fix_invoice_amount +msgid "Fix Amount" +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/discount_config.py:30 +#, python-format +msgid "Fix amount (%s) is greater than configuration Amount (%s)!" +msgstr "" + +#. module: account_discount +#: selection:account.invoice,discount_method:0 +msgid "Fixed" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_res_config_settings_global_discount_invoice_line +msgid "Global Discounts" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_invoice_gross_amount +msgid "Gross Amount" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_discount_config_group_id +msgid "Groups" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_discount_config_id +msgid "ID" +msgstr "" + +#. module: account_discount +#: model:ir.model,name:account_discount.model_account_invoice +msgid "Invoice" +msgstr "" + +#. module: account_discount +#: model:ir.ui.view,arch_db:account_discount.res_config_settings_view_form_invoice_discount_form +msgid "Invoice Discount" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_discount_config___last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_discount_config_write_uid +msgid "Last Updated by" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_account_discount_config_write_date +msgid "Last Updated on" +msgstr "" + +#. module: account_discount +#: selection:account.invoice,discount_method:0 +#: model:ir.model.fields,field_description:account_discount.field_account_discount_config_percentage +msgid "Percentage" +msgstr "" + +#. module: account_discount +#: model:ir.model.fields,field_description:account_discount.field_res_config_settings_global_discount_percentage_invoice +msgid "Percentage (%)" +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/discount_config.py:44 +#, python-format +msgid "Percentage (%s) is greater than configuration Percentage (%s)!" +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/account_invoice.py:95 +#, python-format +msgid "Percentage should be between 0% to 100%" +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/discount_config.py:38 +#, python-format +msgid "Percentage should be between 0% to 100%!" +msgstr "" + +#. module: account_discount +#: model:ir.ui.view,arch_db:account_discount.inherit_account_invoice_form +msgid "Subtotal" +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/account_invoice.py:98 +#, python-format +msgid "You are not allowed to apply Discount Percentage (%s) more than configured Discount Percentage (%s) in configuration setting!" +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/account_invoice.py:107 +#, python-format +msgid "You are not allowed to apply Discount Percentage(%s) more than configured Discount Percentage (%s) in configuration setting!" +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/account_invoice.py:138 +#, python-format +msgid "You're not allowed to apply this amount of discount as discount Amount (%s) is greater than Configuration Amount (%s)." +msgstr "" + +#. module: account_discount +#: code:addons/account_discount/models/account_invoice.py:129 +#, python-format +msgid "You're not allowed to apply this amount of discount as discount Amount (%s) is greater than assign Fix Amount (%s)." +msgstr "" + +#. module: account_discount +#: model:ir.model,name:account_discount.model_account_discount_config +msgid "account.discount.config" +msgstr "" + +#. module: account_discount +#: model:ir.model,name:account_discount.model_res_config_settings +msgid "res.config.settings" +msgstr "" + diff --git a/addons/account_discount/models/__init__.py b/addons/account_discount/models/__init__.py new file mode 100644 index 00000000..90260aba --- /dev/null +++ b/addons/account_discount/models/__init__.py @@ -0,0 +1,5 @@ +# Part of Flectra See LICENSE file for full copyright and licensing details. + +from . import res_config_settings +from . import discount_config +from . import account_invoice diff --git a/addons/account_discount/models/account_invoice.py b/addons/account_discount/models/account_invoice.py new file mode 100644 index 00000000..ea87ba8c --- /dev/null +++ b/addons/account_discount/models/account_invoice.py @@ -0,0 +1,143 @@ +# Part of Flectra See LICENSE file for full copyright and licensing details. + +from flectra import models, fields, api, _ +from flectra.tools.misc import formatLang +from flectra.exceptions import Warning + + +class AccountInvoice(models.Model): + _inherit = "account.invoice" + + @api.multi + @api.depends('discount_amount', 'discount_per', 'amount_untaxed') + def _get_discount(self): + total_discount = 0.0 + for record in self: + for invoice_line_id in record.invoice_line_ids: + total_price = ( + invoice_line_id.quantity * invoice_line_id.price_unit) + total_discount += \ + (total_price * invoice_line_id.discount) / 100 + record.discount = record.currency_id.round(total_discount) + + @api.multi + @api.depends('invoice_line_ids', 'discount_per', 'discount_amount') + def _get_total_amount(self): + for invoice_id in self: + invoice_id.gross_amount = sum( + [line_id.quantity * line_id.price_unit + for line_id in invoice_id.invoice_line_ids]) + + discount_method = fields.Selection( + [('fixed', 'Fixed'), ('per', 'Percentage')], string="Discount Method") + discount_amount = fields.Float(string="Discount Amount") + discount_per = fields.Float(string="Discount (%)") + discount = fields.Monetary( + string='Discount', readonly=True, compute='_get_discount', + track_visibility='always') + gross_amount = fields.Float(string="Gross Amount", + compute='_get_total_amount', store=True) + + @api.multi + def calculate_discount(self): + self._check_constrains() + for line in self.invoice_line_ids: + line.write({'discount': 0.0}) + amount_untaxed = self.amount_untaxed + if self.discount_method == 'per': + for line in self.invoice_line_ids: + line.write({'discount': line.discount + self.discount_per}) + else: + for line in self.invoice_line_ids: + discount_value_ratio = \ + (self.discount_amount * line.price_subtotal) / \ + amount_untaxed + discount_per_ratio = \ + (discount_value_ratio * 100) / line.price_subtotal + line.write({'discount': line.discount + discount_per_ratio}) + + @api.constrains('discount_per', 'discount_amount', 'invoice_line_ids') + def _check_constrains(self): + self.onchange_discount_per() + self.onchange_discount_amount() + + @api.onchange('discount_method') + def onchange_discount_method(self): + self.discount_amount = 0.0 + self.discount_per = 0.0 + if self.discount_method and not self.invoice_line_ids: + raise Warning('No Invoice Line(s) were found!') + + @api.multi + def get_maximum_per_amount(self): + account_dis_config_obj = self.env['account.discount.config'] + max_percentage = 0 + max_amount = 0 + check_group = False + for groups_id in self.env.user.groups_id: + account_dis_config_id = account_dis_config_obj.search( + [('group_id', '=', groups_id.id)]) + if account_dis_config_id: + check_group = True + if account_dis_config_id.percentage > max_percentage: + max_percentage = account_dis_config_id.percentage + if account_dis_config_id.fix_amount > max_amount: + max_amount = account_dis_config_id.fix_amount + return {'max_percentage': max_percentage, + 'max_amount': max_amount, 'check_group': check_group} + + @api.onchange('discount_per') + def onchange_discount_per(self): + values = self.get_maximum_per_amount() + if self.discount_method == 'per' and ( + self.discount_per > 100 or self.discount_per < 0) \ + and values.get('check_group', False): + raise Warning(_("Percentage should be between 0% to 100%")) + if self.discount_per > values.get('max_percentage', False) \ + and values.get('check_group', False): + raise Warning(_("You are not allowed to apply Discount Percentage " + "(%s) more than configured Discount Percentage " + "(%s) in configuration setting!") % ( + formatLang(self.env, self.discount_per, digits=2), + formatLang(self.env, values['max_percentage'], digits=2))) + config_id = self.env[ + 'res.config.settings'].search([], order='id desc', limit=1) + if config_id and config_id.global_discount_invoice_apply: + if config_id.global_discount_percentage_invoice < self.discount_per: + raise Warning(_("You are not allowed to apply Discount " + "Percentage(%s) more than configured Discount" + " Percentage (%s) in configuration setting!" + ) % ( + formatLang(self.env, self.discount_per, digits=2), + formatLang(self.env, config_id.global_discount_percentage_invoice, + digits=2))) + + @api.onchange('discount_amount') + def onchange_discount_amount(self): + if self.discount_method == 'per': + return True + values = self.get_maximum_per_amount() + if self.discount < 0: + raise Warning(_("Discount should be less than Gross Amount")) + if self.discount > self.gross_amount: + raise Warning(_("Discount (%s) should be less than " + "Gross Amount (%s).") % ( + formatLang(self.env, self.discount, digits=2), + formatLang(self.env, self.gross_amount, digits=2))) + if self.discount > values.get('max_amount', False) \ + and values.get('check_group', False): + raise Warning(_("You're not allowed to apply this amount of " + "discount as discount Amount (%s) is greater than" + " assign Fix Amount (%s).") % ( + formatLang(self.env, self.discount, digits=2), + formatLang(self.env, values['max_amount'], digits=2))) + config_id = self.env[ + 'res.config.settings'].search([], order='id desc', limit=1) + if config_id and config_id.global_discount_invoice_apply: + if config_id.global_discount_fix_invoice_amount < self.discount_amount: + raise Warning(_("You're not allowed to apply this amount of" + " discount as discount Amount (%s) is greater" + " than Configuration Amount (%s).") % ( + formatLang(self.env, self.discount, digits=2), + formatLang(self.env, config_id.global_discount_fix_invoice_amount, + digits=2))) diff --git a/addons/account_discount/models/discount_config.py b/addons/account_discount/models/discount_config.py new file mode 100644 index 00000000..a813c426 --- /dev/null +++ b/addons/account_discount/models/discount_config.py @@ -0,0 +1,49 @@ +# Part of Flectra See LICENSE file for full copyright and licensing details. + +from flectra import api, fields, models, _ +from flectra.tools.misc import formatLang + + +class AccountDiscountConfig(models.Model): + _name = 'account.discount.config' + + group_id = fields.Many2one('res.groups', 'Groups', required=True) + fix_amount = fields.Float('Fix Amount', required=True) + percentage = fields.Float('Percentage', required=True) + + @api.constrains('group_id') + def _check_already_exist(self): + check_name = self.search( + [('id', '!=', self.id), + ('group_id.name', '=', self.group_id.name)]) + if check_name: + raise ValueError( + _("Assigned group already exist!")) + + @api.constrains('fix_amount') + def _check_fix_amount_value(self): + config_id = self.env['res.config.settings'].search( + [], order='id desc', limit=1) + if config_id and config_id.global_discount_invoice_apply \ + and config_id.global_discount_fix_invoice_amount < self.fix_amount: + raise ValueError( + _("Fix amount (%s) is greater than configuration Amount (%s)!" + ) % (formatLang( + self.env, self.fix_amount, digits=2), formatLang( + self.env, config_id.global_discount_fix_invoice_amount, digits=2))) + + @api.constrains('percentage') + def _check_percentage(self): + if self.percentage < 0 or self.percentage > 100: + raise ValueError(_("Percentage should be between 0% to 100%!")) + config_id = self.env[ + 'res.config.settings'].search([], order='id desc', limit=1) + if config_id and config_id.global_discount_invoice_apply \ + and config_id.global_discount_percentage_invoice < self.percentage: + raise ValueError( + _("Percentage (%s) is greater than configuration Percentage " + "(%s)!") % (formatLang( + self.env, self.percentage, digits=2), + formatLang(self.env, + config_id.global_discount_percentage_invoice, + digits=2))) diff --git a/addons/account_discount/models/res_config_settings.py b/addons/account_discount/models/res_config_settings.py new file mode 100644 index 00000000..81ad7870 --- /dev/null +++ b/addons/account_discount/models/res_config_settings.py @@ -0,0 +1,61 @@ +# Part of Flectra See LICENSE file for full copyright and licensing details. + +from flectra import api, fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + global_discount_invoice_line = fields.Boolean( + "Global Discounts", + implied_group='account_discount.global_discount_invoice_line') + global_discount_invoice_apply = fields.Boolean( + "Do you want to set global discount limit?", + implied_group='account_discount.global_discount_invoice_apply') + global_discount_fix_invoice_amount = fields.Integer( + 'Fix Amount', + implied_group='account_discount.global_discount_invoice_apply') + global_discount_percentage_invoice = fields.Integer( + 'Percentage (%)', + implied_group='account_discount.global_discount_percentage_invoice') + + @api.onchange('global_discount_invoice_line') + def onchange_global_discount_invoice_line(self): + if not self.global_discount_invoice_line: + self.global_discount_invoice_apply = False + + @api.onchange('global_discount_invoice_apply') + def onchange_global_discount_invoice_apply(self): + if not self.global_discount_invoice_apply: + self.global_discount_fix_invoice_amount = False + + @api.model + def get_values(self): + res = super(ResConfigSettings, self).get_values() + res.update( + global_discount_invoice_line=self.env[ + 'ir.config_parameter'].sudo().get_param( + 'global_discount_invoice_line'), + global_discount_invoice_apply=self.env[ + 'ir.config_parameter'].sudo().get_param( + 'global_discount_invoice_apply'), + global_discount_fix_invoice_amount=int(self.env[ + 'ir.config_parameter'].sudo().get_param( + 'global_discount_fix_invoice_amount')), + global_discount_percentage_invoice=int(self.env[ + 'ir.config_parameter'].sudo().get_param( + 'global_discount_percentage_invoice')), + ) + return res + + def set_values(self): + super(ResConfigSettings, self).set_values() + params = self.env['ir.config_parameter'].sudo() + params.set_param('global_discount_invoice_line', + self.global_discount_invoice_line) + params.set_param('global_discount_invoice_apply', + self.global_discount_invoice_apply) + params.set_param('global_discount_fix_invoice_amount', + self.global_discount_fix_invoice_amount) + params.set_param('global_discount_percentage_invoice', + self.global_discount_percentage_invoice) diff --git a/addons/account_discount/report/custom_invoice_report.xml b/addons/account_discount/report/custom_invoice_report.xml new file mode 100644 index 00000000..5d4c7d5b --- /dev/null +++ b/addons/account_discount/report/custom_invoice_report.xml @@ -0,0 +1,59 @@ + + + + \ No newline at end of file diff --git a/addons/account_discount/report/report_menu.xml b/addons/account_discount/report/report_menu.xml new file mode 100644 index 00000000..c43d7519 --- /dev/null +++ b/addons/account_discount/report/report_menu.xml @@ -0,0 +1,12 @@ + + + + diff --git a/addons/account_discount/security/ir.model.access.csv b/addons/account_discount/security/ir.model.access.csv new file mode 100644 index 00000000..5c811c04 --- /dev/null +++ b/addons/account_discount/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_account_discount_config,access_account_discount_config,model_account_discount_config,base.group_system,1,1,1,1 +access_account_discount_config_all,access_account_discount_config_all,model_account_discount_config,,1,0,0,0 diff --git a/addons/account_discount/static/description/icon.png b/addons/account_discount/static/description/icon.png new file mode 100644 index 00000000..b44ec8a1 Binary files /dev/null and b/addons/account_discount/static/description/icon.png differ diff --git a/addons/account_discount/tests/__init__.py b/addons/account_discount/tests/__init__.py new file mode 100644 index 00000000..0834299d --- /dev/null +++ b/addons/account_discount/tests/__init__.py @@ -0,0 +1,5 @@ +# Part of Flectra See LICENSE file for full copyright and licensing details. + +from . import discount_common +from . import test_01_account_discount +from . import test_02_account_discount_invoice diff --git a/addons/account_discount/tests/discount_common.py b/addons/account_discount/tests/discount_common.py new file mode 100644 index 00000000..28c28941 --- /dev/null +++ b/addons/account_discount/tests/discount_common.py @@ -0,0 +1,22 @@ +# Part of Flectra See LICENSE file for full copyright and licensing details. + +from flectra.tests.common import TransactionCase + + +class TestDiscountCommon(TransactionCase): + def setUp(self): + super(TestDiscountCommon, self).setUp() + self.config = self.env['res.config.settings'].create({ + 'global_discount_invoice_line': True, + 'global_discount_invoice_apply': True, + 'global_discount_fix_invoice_amount': 5000, + 'global_discount_percentage_invoice': 50, + }) + self.config.onchange_global_discount_invoice_line() + self.config.onchange_global_discount_invoice_apply() + self.config.set_values() + self.disc_config_1 = self.env['account.discount.config'].create({ + 'group_id': self.env.ref('account.group_account_user').id, + 'fix_amount': 3000.0, + 'percentage': 20.0, + }) diff --git a/addons/account_discount/tests/test_01_account_discount.py b/addons/account_discount/tests/test_01_account_discount.py new file mode 100644 index 00000000..3a4bf69d --- /dev/null +++ b/addons/account_discount/tests/test_01_account_discount.py @@ -0,0 +1,89 @@ +# Part of Flectra See LICENSE file for full copyright and licensing details. + +from .discount_common import TestDiscountCommon +import logging +import time + +class TestInvoiceDiscount(TestDiscountCommon): + def setUp(self): + super(TestInvoiceDiscount, self).setUp() + + def discount_01_set_fixamount(self): + self.account_id = self.env['account.account'].create({ + 'name': 'Test', + 'code': 'DA', + 'user_type_id':self.env.ref("account.data_account_type_revenue").id, + }) + + invoice_id = self.env['account.invoice'].create({ + 'name': 'Discount Invoice Test Fixed', + 'partner_id': self.env.ref("base.res_partner_4").id, + 'currency_id': self.env.ref('base.USD').id, + 'account_id': self.account_id.id, + 'type': 'out_invoice', + 'date_invoice': time.strftime('%Y') + '-03-12', + }) + invoice_id.onchange_discount_method() + invoice_id.write({ + 'discount_method': 'fixed', + 'discount_amount': 100, + }) + self.env['account.invoice.line'].create({ + 'product_id': self.env.ref("product.product_product_10").id, + 'quantity': 10, + 'price_unit': 400, + 'invoice_id': invoice_id.id, + 'name': 'Mouse, Optical', + 'account_id': self.account_id.id, + }) + self.env['account.invoice.line'].create({ + 'product_id': self.env.ref("product.product_product_12").id, + 'quantity': 30, + 'price_unit': 250, + 'invoice_id': invoice_id.id, + 'name': 'Mouse, Wireless', + 'account_id': self.account_id.id, + }) + self.assertTrue(invoice_id, 'Invoice: no invoice created') + invoice_id._check_constrains() + invoice_id.onchange_discount_per() + invoice_id.onchange_discount_amount() + logging.info('Successful: Invoice Created!') + invoice_id.calculate_discount() + return invoice_id + + def discount_02_set_percentages(self): + self.account_id = self.env['account.account'].create({ + 'name': 'Test', + 'code': 'DA', + 'user_type_id':self.env.ref("account.data_account_type_revenue").id, + }) + invoice_id = self.env['account.invoice'].create({ + 'name': 'Discount Invoice Test', + 'partner_id': self.env.ref("base.res_partner_4").id, + 'currency_id': self.env.ref('base.USD').id, + 'account_id': self.account_id.id, + 'type': 'out_invoice', + 'discount_method': 'per', + 'discount_per': 10, + 'date_invoice': time.strftime('%Y') + '-03-12', + }) + self.env['account.invoice.line'].create({ + 'product_id': self.env.ref("product.product_product_10").id, + 'quantity': 10, + 'price_unit': 400, + 'discount': 10, + 'invoice_id': invoice_id.id, + 'name': 'Mouse, Optical', + 'account_id': self.account_id.id, + }) + self.env['account.invoice.line'].create({ + 'product_id': self.env.ref("product.product_product_12").id, + 'quantity': 30, + 'price_unit': 250, + 'discount': 10, + 'invoice_id': invoice_id.id, + 'name': 'Mouse, Wireless', + 'account_id': self.account_id.id, + }) + return invoice_id diff --git a/addons/account_discount/tests/test_02_account_discount_invoice.py b/addons/account_discount/tests/test_02_account_discount_invoice.py new file mode 100644 index 00000000..c705f448 --- /dev/null +++ b/addons/account_discount/tests/test_02_account_discount_invoice.py @@ -0,0 +1,26 @@ +# Part of Flectra See LICENSE file for full copyright and licensing details. + +from .test_01_account_discount import TestInvoiceDiscount +import logging + +class TestDiscountInvoice(TestInvoiceDiscount): + def setUp(self): + super(TestDiscountInvoice, self).setUp() + + def test_01_dp_fixed_amount(self): + invoice = self.discount_01_set_fixamount() + invoice.action_invoice_open() + + def test_02_percentage_discount(self): + invoice_id = self.discount_02_set_percentages() + invoice_id._check_constrains() + invoice_id.onchange_discount_per() + invoice_id.onchange_discount_amount() + self.assertTrue(invoice_id, 'Invoice: no invoice created') + logging.info('Successful: Invoice Created!') + invoice_id.write({ + 'discount_method': 'per', + 'discount_per': 20.0, + }) + invoice_id.calculate_discount() + invoice_id.action_invoice_open() diff --git a/addons/account_discount/views/account_invoice_views.xml b/addons/account_discount/views/account_invoice_views.xml new file mode 100644 index 00000000..a47dd4dd --- /dev/null +++ b/addons/account_discount/views/account_invoice_views.xml @@ -0,0 +1,37 @@ + + + + + account.invoice.inherit.form + account.invoice + + + + + + +
+ + + + + +
+
+
+
+
diff --git a/addons/account_discount/views/discount_config_view.xml b/addons/account_discount/views/discount_config_view.xml new file mode 100644 index 00000000..cb7a0c17 --- /dev/null +++ b/addons/account_discount/views/discount_config_view.xml @@ -0,0 +1,27 @@ + + + + account.discount.config + account.discount.config + + + + + + + + + + + + Discounts + account.discount.config + form + tree + + + + + diff --git a/addons/account_discount/views/res_config_settings_views.xml b/addons/account_discount/views/res_config_settings_views.xml new file mode 100644 index 00000000..2a608923 --- /dev/null +++ b/addons/account_discount/views/res_config_settings_views.xml @@ -0,0 +1,45 @@ + + + + res.config.settings.view.form.inherit.discount.account + res.config.settings + + + + +

Invoice Discount

+
+
+
+ +
+
+
+
+
+
+
+
+