diff --git a/ext/3rd-party-addons/global_discount/__init__.py b/ext/3rd-party-addons/global_discount/__init__.py new file mode 100755 index 00000000..fa7ea9f7 --- /dev/null +++ b/ext/3rd-party-addons/global_discount/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +from . import models + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/ext/3rd-party-addons/global_discount/__manifest__.py b/ext/3rd-party-addons/global_discount/__manifest__.py new file mode 100755 index 00000000..d3ece33f --- /dev/null +++ b/ext/3rd-party-addons/global_discount/__manifest__.py @@ -0,0 +1,44 @@ +# -*- encoding: utf-8 -*- +########################################################################### +# +# Copyright (C) 2016 - Today Turkesh Patel. +# +# @author Turkesh Patel +########################################################################### + +{ + 'name': 'Sale, Purchase and Invoice Global Discounts', + 'category': 'Accounting', + 'version': '1.0', + 'author' : 'Almighty Consulting Services', + 'support': 'info@almightycs.com', + 'website' : 'http://www.almightycs.com', + 'summary': """Apply Global Discounts on Sale, Purchase Orders and Invoice based on fixed amounts and percentage""", + 'description': """Apply Global Discounts on Sale, Purchase Orders and Invoice based on fixed amounts and percentage. + Global Discounts + Global Discount + Fixed Amount Discount + Discount on Total + Discount in Purchase + Discount in Invoice + Discount in Sale + Global Discount in Purchase + Global Discount in Invoice + Global Discount in Sale""", + 'depends': ['purchase','sale_management','account'], + 'data': [ + 'views/purchase_view.xml', + 'views/sale_view.xml', + 'views/invoice_view.xml', + 'views/res_config_view.xml', + ], + 'images': [ + 'static/description/discount_cover_almightycs_turkesh.png', + ], + 'installable': True, + 'auto_install': False, + 'price': 35, + 'currency': 'EUR', +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/ext/3rd-party-addons/global_discount/models/__init__.py b/ext/3rd-party-addons/global_discount/models/__init__.py new file mode 100755 index 00000000..0dd1d10f --- /dev/null +++ b/ext/3rd-party-addons/global_discount/models/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +from . import sale +from . import purchase +from . import invoice +from . import res_config + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/ext/3rd-party-addons/global_discount/models/invoice.py b/ext/3rd-party-addons/global_discount/models/invoice.py new file mode 100755 index 00000000..378df230 --- /dev/null +++ b/ext/3rd-party-addons/global_discount/models/invoice.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- + +from odoo import fields, models, api, _ +from odoo.exceptions import UserError + +class Invoice(models.Model): + _inherit = "account.invoice" + + global_discount = fields.Boolean("Add Global Disocunt", readonly=True, states={'draft': [('readonly', False)]},) + discount_type = fields.Selection([('fixed','Fixed'),('percentage','Percentage')], + "Disocunt Type", readonly=True, states={'draft': [('readonly', False)]}, default='fixed') + discount_amount = fields.Float("Disocunt Amount", readonly=True, states={'draft': [('readonly', False)]},) + discount_percentage = fields.Float("Disocunt Percentage", readonly=True, states={'draft': [('readonly', False)]},) + + @api.multi + def _discount_unset(self): + if self.env.user.company_id.invoice_discount_product_id: + self.env['account.invoice.line'].search([('invoice_id', 'in', self.ids), ('product_id', '=', self.env.user.company_id.invoice_discount_product_id.id)]).unlink() + + @api.multi + def create_discount(self): + InvoiceLine = self.env['account.invoice.line'] + + product_id = self.env.user.company_id.invoice_discount_product_id + if not product_id: + raise UserError(_('Please set Invoice Discount product in General Settings first.')) + + # Remove Discount line first + self._discount_unset() + + account_id = product_id.property_account_income_id.id + if not account_id: + prop = self.env['ir.property'].get('property_account_income_categ_id', 'product.category') + account_id = prop and prop.id or False + + for invoice in self: + amount = 0 + if invoice.discount_type == 'fixed': + amount = invoice.discount_amount + if invoice.discount_type == 'percentage': + amount = (invoice.amount_total * invoice.discount_percentage)/100 + + # Apply fiscal position + taxes = product_id.taxes_id.filtered(lambda t: t.company_id.id == invoice.company_id.id) + taxes_ids = taxes.ids + if invoice.partner_id and self.fiscal_position_id: + taxes_ids = self.fiscal_position_id.map_tax(taxes, product_id, invoice.partner_id).ids + + # Create the Invoice line + InvoiceLine.create({ + 'name': product_id.name, + 'price_unit': -amount, + 'account_id': account_id, + 'quantity': 1.0, + 'discount': 0.0, + 'uom_id': product_id.uom_id.id, + 'product_id': product_id.id, + 'invoice_id': invoice.id, + 'invoice_line_tax_ids': [(6, 0, taxes_ids)], + 'sequence': 100, + }) + return True diff --git a/ext/3rd-party-addons/global_discount/models/purchase.py b/ext/3rd-party-addons/global_discount/models/purchase.py new file mode 100755 index 00000000..c66923d5 --- /dev/null +++ b/ext/3rd-party-addons/global_discount/models/purchase.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +from odoo import fields, models, api, _ +from odoo.exceptions import UserError + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + global_discount = fields.Boolean("Add Global Disocunt", readonly=True, states={'draft': [('readonly', False)]},) + discount_type = fields.Selection([('fixed','Fixed'),('percentage','Percentage')], + "Disocunt Type", readonly=True, states={'draft': [('readonly', False)]}, default='fixed') + discount_amount = fields.Float("Disocunt Amount", readonly=True, states={'draft': [('readonly', False)]},) + discount_percentage = fields.Float("Disocunt Percentage", readonly=True, states={'draft': [('readonly', False)]},) + + @api.multi + def _discount_unset(self): + if self.env.user.company_id.purchase_discount_product_id: + self.env['purchase.order.line'].search([('order_id', 'in', self.ids), ('product_id', '=', self.env.user.company_id.purchase_discount_product_id.id)]).unlink() + + @api.multi + def create_discount(self): + Line = self.env['purchase.order.line'] + + product_id = self.env.user.company_id.purchase_discount_product_id + if not product_id: + raise UserError(_('Please set Purchase Discount product in General Settings first.')) + + # Remove Discount line first + self._discount_unset() + + for order in self: + amount = 0 + if order.discount_type == 'fixed': + amount = order.discount_amount + if order.discount_type == 'percentage': + amount = (order.amount_total * order.discount_percentage)/100 + + # Create the Purchase line + Line.create({ + 'name': product_id.name, + 'price_unit': -amount, + 'product_qty': 1.0, + 'product_uom': product_id.uom_id.id, + 'product_id': product_id.id, + 'order_id': order.id, + 'date_planned': fields.datetime.now(), + #'sequence': 100, + }) + return True diff --git a/ext/3rd-party-addons/global_discount/models/res_config.py b/ext/3rd-party-addons/global_discount/models/res_config.py new file mode 100644 index 00000000..777036fb --- /dev/null +++ b/ext/3rd-party-addons/global_discount/models/res_config.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- + +from odoo import fields, models, api + + +class ResCompany(models.Model): + _inherit = "res.company" + + purchase_discount_product_id = fields.Many2one('product.product', string='Purchase Discount Product') + sale_discount_product_id = fields.Many2one('product.product', string='Sale Discount Product') + invoice_discount_product_id = fields.Many2one('product.product', string='Invoice Discount Product') + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + purchase_discount_product_id = fields.Many2one('product.product', string='Purchase Discount Product') + sale_discount_product_id = fields.Many2one('product.product', string='Sale Discount Product') + invoice_discount_product_id = fields.Many2one('product.product', string='Invoice Discount Product') + + @api.model + def get_values(self): + res = super(ResConfigSettings, self).get_values() + res.update( + purchase_discount_product_id=self.env.user.company_id.purchase_discount_product_id and self.env.user.company_id.purchase_discount_product_id.id or False, + sale_discount_product_id=self.env.user.company_id.sale_discount_product_id and self.env.user.company_id.sale_discount_product_id.id or False, + invoice_discount_product_id=self.env.user.company_id.invoice_discount_product_id and self.env.user.company_id.invoice_discount_product_id.id or False, + ) + return res + + @api.multi + def set_values(self): + super(ResConfigSettings, self).set_values() + if not self.env.user._is_admin(): + raise AccessError(_("Only administrators can change the settings")) + + self.env.user.company_id.purchase_discount_product_id = self.purchase_discount_product_id.id + self.env.user.company_id.sale_discount_product_id = self.sale_discount_product_id.id + self.env.user.company_id.invoice_discount_product_id = self.invoice_discount_product_id.id + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/ext/3rd-party-addons/global_discount/models/sale.py b/ext/3rd-party-addons/global_discount/models/sale.py new file mode 100755 index 00000000..d9d92b57 --- /dev/null +++ b/ext/3rd-party-addons/global_discount/models/sale.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +from odoo import fields, models, api, _ +from odoo.exceptions import UserError + +class SaleOrder(models.Model): + _inherit = "sale.order" + + global_discount = fields.Boolean("Add Global Disocunt", readonly=True, states={'draft': [('readonly', False)]},) + discount_type = fields.Selection([('fixed','Fixed'),('percentage','Percentage')], + "Disocunt Type", readonly=True, states={'draft': [('readonly', False)]}, default='fixed') + discount_amount = fields.Float("Disocunt Amount", readonly=True, states={'draft': [('readonly', False)]},) + discount_percentage = fields.Float("Disocunt Percentage", readonly=True, states={'draft': [('readonly', False)]},) + + @api.multi + def _discount_unset(self): + if self.env.user.company_id.sale_discount_product_id: + self.env['sale.order.line'].search([('order_id', 'in', self.ids), ('product_id', '=', self.env.user.company_id.sale_discount_product_id.id)]).unlink() + + @api.multi + def create_discount(self): + Line = self.env['sale.order.line'] + + product_id = self.env.user.company_id.sale_discount_product_id + if not product_id: + raise UserError(_('Please set Sale Discount product in General Settings first.')) + + # Remove Discount line first + self._discount_unset() + + for order in self: + amount = 0 + if order.discount_type == 'fixed': + amount = order.discount_amount + if order.discount_type == 'percentage': + amount = (order.amount_total * order.discount_percentage)/100 + + # Create the Sale line + Line.create({ + 'name': product_id.name, + 'price_unit': -amount, + 'quantity': 1.0, + 'discount': 0.0, + 'product_uom': product_id.uom_id.id, + 'product_id': product_id.id, + 'order_id': order.id, + 'sequence': 100, + }) + return True diff --git a/ext/3rd-party-addons/global_discount/static/description/acs.png b/ext/3rd-party-addons/global_discount/static/description/acs.png new file mode 100644 index 00000000..fbdc8bbd Binary files /dev/null and b/ext/3rd-party-addons/global_discount/static/description/acs.png differ diff --git a/ext/3rd-party-addons/global_discount/static/description/bill_discount_almightycs_odoo_turkesh_patel.png b/ext/3rd-party-addons/global_discount/static/description/bill_discount_almightycs_odoo_turkesh_patel.png new file mode 100644 index 00000000..5a8873ee Binary files /dev/null and b/ext/3rd-party-addons/global_discount/static/description/bill_discount_almightycs_odoo_turkesh_patel.png differ diff --git a/ext/3rd-party-addons/global_discount/static/description/discount_cover_almightycs_turkesh.png b/ext/3rd-party-addons/global_discount/static/description/discount_cover_almightycs_turkesh.png new file mode 100644 index 00000000..afb51885 Binary files /dev/null and b/ext/3rd-party-addons/global_discount/static/description/discount_cover_almightycs_turkesh.png differ diff --git a/ext/3rd-party-addons/global_discount/static/description/discount_settings_almightycs_odoo_turkesh_patel.png b/ext/3rd-party-addons/global_discount/static/description/discount_settings_almightycs_odoo_turkesh_patel.png new file mode 100644 index 00000000..0b018b80 Binary files /dev/null and b/ext/3rd-party-addons/global_discount/static/description/discount_settings_almightycs_odoo_turkesh_patel.png differ diff --git a/ext/3rd-party-addons/global_discount/static/description/icon.png b/ext/3rd-party-addons/global_discount/static/description/icon.png new file mode 100644 index 00000000..54d0484e Binary files /dev/null and b/ext/3rd-party-addons/global_discount/static/description/icon.png differ diff --git a/ext/3rd-party-addons/global_discount/static/description/index.html b/ext/3rd-party-addons/global_discount/static/description/index.html new file mode 100644 index 00000000..6f77af0f --- /dev/null +++ b/ext/3rd-party-addons/global_discount/static/description/index.html @@ -0,0 +1,109 @@ + + + + +
+
+
+

Sale, Purchase and Invoice Global Discounts.


In many cases we need to give some global discount on order. To handle such cases we have added this module where you can add discounts based on percentage or fixed amount.
You will need to configure discount product in general settings and that product will be added as discount on Order. So you can set proper account on product and get expected analysis for account in related accounting reports

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

Other Configuration

+

To use this module no technical knowledge is required even no configuration is needed. Just install module and functionality is ready to use. For more customization and help contactus.

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

+

Do you need help?

+

+ Let's offer you the best services! +

+

+ Contact us by our official channels. +

+

+ Skype: turkesh4friends +

+
+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • + +
  • + +
  • +
+
+
+ +
+
+ diff --git a/ext/3rd-party-addons/global_discount/static/description/invoice_discount_almightycs_odoo_turkesh_patel.png b/ext/3rd-party-addons/global_discount/static/description/invoice_discount_almightycs_odoo_turkesh_patel.png new file mode 100644 index 00000000..99f48d1f Binary files /dev/null and b/ext/3rd-party-addons/global_discount/static/description/invoice_discount_almightycs_odoo_turkesh_patel.png differ diff --git a/ext/3rd-party-addons/global_discount/static/description/purchase_discount_almightycs_odoo_turkesh_patel.png b/ext/3rd-party-addons/global_discount/static/description/purchase_discount_almightycs_odoo_turkesh_patel.png new file mode 100644 index 00000000..ea75d731 Binary files /dev/null and b/ext/3rd-party-addons/global_discount/static/description/purchase_discount_almightycs_odoo_turkesh_patel.png differ diff --git a/ext/3rd-party-addons/global_discount/static/description/sale_discount_almightycs_odoo_turkesh_patel.png b/ext/3rd-party-addons/global_discount/static/description/sale_discount_almightycs_odoo_turkesh_patel.png new file mode 100644 index 00000000..87f6be7a Binary files /dev/null and b/ext/3rd-party-addons/global_discount/static/description/sale_discount_almightycs_odoo_turkesh_patel.png differ diff --git a/ext/3rd-party-addons/global_discount/views/invoice_view.xml b/ext/3rd-party-addons/global_discount/views/invoice_view.xml new file mode 100755 index 00000000..34ef5996 --- /dev/null +++ b/ext/3rd-party-addons/global_discount/views/invoice_view.xml @@ -0,0 +1,50 @@ + + + + + + account.invoice.form.withholding + account.invoice + + + + + + + + + + + + account.invoice.form.withholding + account.invoice + + + + + + + + + + diff --git a/ext/3rd-party-addons/global_discount/views/purchase_view.xml b/ext/3rd-party-addons/global_discount/views/purchase_view.xml new file mode 100755 index 00000000..4d769a32 --- /dev/null +++ b/ext/3rd-party-addons/global_discount/views/purchase_view.xml @@ -0,0 +1,27 @@ + + + + + + purchase.order.form.rounding + purchase.order + + + + + + + + + + diff --git a/ext/3rd-party-addons/global_discount/views/res_config_view.xml b/ext/3rd-party-addons/global_discount/views/res_config_view.xml new file mode 100644 index 00000000..8ab6f6ea --- /dev/null +++ b/ext/3rd-party-addons/global_discount/views/res_config_view.xml @@ -0,0 +1,38 @@ + + + + + res.config.settings + res.config.settings + + + +
+

Discount Configuration

+
+
+
+
+
+
+
+
+
+
+ +
diff --git a/ext/3rd-party-addons/global_discount/views/sale_view.xml b/ext/3rd-party-addons/global_discount/views/sale_view.xml new file mode 100755 index 00000000..05c41ae7 --- /dev/null +++ b/ext/3rd-party-addons/global_discount/views/sale_view.xml @@ -0,0 +1,27 @@ + + + + + + sale.order.form.rounding + sale.order + + + + + + + + + +