new dealer discount
parent
d622f142d9
commit
fdfdf10ad4
|
|
@ -0,0 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
###########################################################################
|
||||
#
|
||||
# Copyright (C) 2016 - Today Turkesh Patel. <http://www.almightycs.com>
|
||||
#
|
||||
# @author Turkesh Patel <info@almightycs.com>
|
||||
###########################################################################
|
||||
|
||||
{
|
||||
'name': 'Sale and Invoice Dealer Discounts',
|
||||
'category': 'Accounting',
|
||||
'version': '1.0',
|
||||
'author' : 'TZAustria, derived from Almighty Consulting Services',
|
||||
'support': 'andreas.osim@glaser-co.at',
|
||||
'website': 'https://www.tzaustria.at',
|
||||
'summary': """Apply Dealer Discounts on Sale Orders and Invoice based on fixed amounts and percentage, BUT NOT for special products (based on material_type)""",
|
||||
'description': """Apply Dealer Discounts on Sale Orders and Invoice based on fixed amounts and percentage, BUT NOT for special products (based on material_type)""",
|
||||
'depends': ['purchase','sale_management','account'],
|
||||
'data': [
|
||||
'views/sale_view.xml',
|
||||
'views/invoice_view.xml',
|
||||
'views/res_config_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import sale
|
||||
from . import invoice
|
||||
from . import res_config
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
@ -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"
|
||||
|
||||
dealer_discount = fields.Boolean("Add Dealer Discount", readonly=True, states={'draft': [('readonly', False)]},)
|
||||
dealer_discount_type = fields.Selection([('fixed','Fixed'),('percentage','Percentage')],
|
||||
"Discount Type", readonly=True, states={'draft': [('readonly', False)]}, default='fixed')
|
||||
dealer_discount_amount = fields.Float("Discount Amount", readonly=True, states={'draft': [('readonly', False)]},)
|
||||
dealer_discount_percentage = fields.Float("Discount Percentage", readonly=True, states={'draft': [('readonly', False)]},)
|
||||
|
||||
@api.multi
|
||||
def _dealer_discount_unset(self):
|
||||
if self.env.user.company_id.invoice_dealer_discount_product_id:
|
||||
self.env['account.invoice.line'].search([('invoice_id', 'in', self.ids), ('product_id', '=', self.env.user.company_id.invoice_dealer_discount_product_id.id)]).unlink()
|
||||
|
||||
@api.multi
|
||||
def create_dealer_discount(self):
|
||||
InvoiceLine = self.env['account.invoice.line']
|
||||
|
||||
product_id = self.env.user.company_id.invoice_dealer_discount_product_id
|
||||
if not product_id:
|
||||
raise UserError(_('Please set Invoice Dealer Discount product in General Settings first.'))
|
||||
|
||||
# Remove Discount line first
|
||||
self._dealer_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.dealer_discount_type == 'fixed':
|
||||
amount = invoice.dealer_discount_amount
|
||||
if invoice.dealer_discount_type == 'percentage':
|
||||
amount = (invoice.amount_total * invoice.dealer_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
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import fields, models, api
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
sale_dealer_discount_product_id = fields.Many2one('product.product', string='Sale Dealer Discount Product')
|
||||
invoice_dealer_discount_product_id = fields.Many2one('product.product', string='Invoice Dealer Discount Product')
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
sale_dealer_discount_product_id = fields.Many2one('product.product', string='Sale Dealer Discount Product')
|
||||
invoice_dealer_discount_product_id = fields.Many2one('product.product', string='Invoice Dealer Discount Product')
|
||||
|
||||
@api.model
|
||||
def get_values(self):
|
||||
res = super(ResConfigSettings, self).get_values()
|
||||
res.update(
|
||||
sale_dealer_discount_product_id=self.env.user.company_id.sale_dealer_discount_product_id and self.env.user.company_id.sale_dealer_discount_product_id.id or False,
|
||||
invoice_dealer_discount_product_id=self.env.user.company_id.invoice_dealer_discount_product_id and self.env.user.company_id.invoice_dealer_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.sale_dealer_discount_product_id = self.sale_dealer_discount_product_id.id
|
||||
self.env.user.company_id.invoice_dealer_discount_product_id = self.invoice_dealer_discount_product_id.id
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import fields, models, api, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
dealer_discount = fields.Boolean("Add Dealer Discount", readonly=True, states={'draft': [('readonly', False),],'sent': [('readonly', False)]},)
|
||||
dealer_discount_type = fields.Selection([('fixed','Fixed'),('percentage','Percentage')],
|
||||
"Discount Type", readonly=True, states={'draft': [('readonly', False)],'sent': [('readonly', False)]}, default='percentage')
|
||||
dealer_discount_amount = fields.Float("Discount Amount", readonly=True, states={'draft': [('readonly', False)],'sent': [('readonly', False)]},)
|
||||
dealer_discount_percentage = fields.Float("Discount Percentage", readonly=True, states={'draft': [('readonly', False)],'sent': [('readonly', False)]},)
|
||||
|
||||
@api.multi
|
||||
def _dealer_discount_unset(self):
|
||||
if self.env.user.company_id.sale_dealer_discount_product_id:
|
||||
self.env['sale.order.line'].search([('order_id', 'in', self.ids), ('product_id', '=', self.env.user.company_id.sale_dealer_discount_product_id.id)]).unlink()
|
||||
|
||||
@api.multi
|
||||
def create_dealer_discount(self):
|
||||
Line = self.env['sale.order.line']
|
||||
|
||||
discount_product_id = self.env.user.company_id.sale_dealer_discount_product_id
|
||||
if not discount_product_id:
|
||||
raise UserError(_('Please set Sale Dealer Discount product in General Settings first.'))
|
||||
|
||||
# Remove Discount line first
|
||||
self._dealer_discount_unset()
|
||||
|
||||
for order in self:
|
||||
amount = 0
|
||||
if order.dealer_discount_type == 'fixed':
|
||||
discount_text = discount_product_id.name
|
||||
amount = order.dealer_discount_amount
|
||||
else:
|
||||
sep = "; "
|
||||
discount_text = "-" + str(order.dealer_discount_percentage) + "% " + discount_product_id.name + ", "
|
||||
discount_pos = ""
|
||||
n=0
|
||||
nd=0
|
||||
for line in order.order_line:
|
||||
n += 1
|
||||
if not line.product_id.product_tmpl_id.material_type_id.no_dealer_discount:
|
||||
nd += 1
|
||||
amount += (line.price_subtotal * order.dealer_discount_percentage)/100
|
||||
discount_pos += str(n)+sep
|
||||
if nd>1:
|
||||
discount_text = discount_text + "Positionen: "
|
||||
else:
|
||||
discount_text = discount_text + "Position: "
|
||||
|
||||
discount_text = discount_text + discount_pos.rstrip(sep)
|
||||
|
||||
if amount > 0:
|
||||
# Create the Sale line
|
||||
Line.create({
|
||||
'name': discount_text,
|
||||
'price_unit': -amount,
|
||||
'product_uom_qty': 1.0,
|
||||
'discount': 0.0,
|
||||
'product_uom': discount_product_id.uom_id.id,
|
||||
'product_id': discount_product_id.id,
|
||||
'order_id': order.id,
|
||||
'sequence': 99999,
|
||||
})
|
||||
|
||||
return True
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
|
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- Invoice View -->
|
||||
<record id="invoice_form" model="ir.ui.view">
|
||||
<field name="name">account.invoice.form.dealer_discount</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//field[@name='user_id']" position="after">
|
||||
<label for="dealer_discount"/>
|
||||
<div name='dealer_discount'>
|
||||
<div>
|
||||
<field name='dealer_discount' class="oe_inline" nolabel="1" attrs="{'invisible': [('state','!=', 'draft')]}"/>
|
||||
<field name='dealer_discount_type' class="oe_inline" nolabel="1" attrs="{'invisible': ['|',('dealer_discount','=', False), ('state','!=', 'draft')], 'required':[('dealer_discount','!=', False)]}"/>
|
||||
<field name='dealer_discount_amount' class="oe_inline" nolabel="1" attrs="{'invisible': ['|','|',('dealer_discount','=', False), ('state','!=', 'draft'),('dealer_discount_type','!=','fixed')]}"/>
|
||||
<field name='dealer_discount_percentage' class="oe_inline" nolabel="1" attrs="{'invisible': ['|','|',('dealer_discount','=', False), ('state','!=', 'draft'),('dealer_discount_type','!=','percentage')]}"/>
|
||||
<button name="create_dealer_discount" string="Add Line" type="object" class="oe_inline fa fa-arrow-right oe_link" attrs="{'invisible': ['|',('dealer_discount','=', False), ('state','!=', 'draft')]}"/>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Bill View -->
|
||||
<record id="invoice_supplier_form" model="ir.ui.view">
|
||||
<field name="name">account.invoice.form.dealer_discount</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//field[@name='date_due']" position="after">
|
||||
<label for="dealer_discount"/>
|
||||
<div name='dealer_discount'>
|
||||
<div>
|
||||
<field name='dealer_discount' class="oe_inline" nolabel="1" attrs="{'invisible': [('state','!=', 'draft')]}"/>
|
||||
<field name='dealer_discount_type' class="oe_inline" nolabel="1" attrs="{'invisible': ['|',('dealer_discount','=', False), ('state','!=', 'draft')], 'required':[('dealer_discount','!=', False)]}"/>
|
||||
<field name='dealer_discount_amount' class="oe_inline" nolabel="1" attrs="{'invisible': ['|','|',('dealer_discount','=', False), ('state','!=', 'draft'),('dealer_discount_type','!=','fixed')]}"/>
|
||||
<field name='dealer_discount_percentage' class="oe_inline" nolabel="1" attrs="{'invisible': ['|','|',('dealer_discount','=', False), ('state','!=', 'draft'),('dealer_discount_type','!=','percentage')]}"/>
|
||||
<button name="create_dealer_discount" string="Add Line" type="object" class="oe_inline fa fa-arrow-right oe_link" attrs="{'invisible': ['|',('dealer_discount','=', False), ('state','!=', 'draft')]}"/>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||
<field name="name">res.config.settings</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="company_id" position="before">
|
||||
<div id="discount">
|
||||
<h2>Dealer Discount Configuration</h2>
|
||||
<div class="row mt16 o_settings_container">
|
||||
<div class="col-xs-12 col-md-6 o_setting_box">
|
||||
<div class="o_setting_right_pane">
|
||||
<label string="Default Dealer Discount Products"/>
|
||||
<div class="content-group">
|
||||
<div class="mt16 row">
|
||||
<label for="sale_dealer_discount_product_id" class="col-xs-3 col-md-3 o_light_label"/>
|
||||
<field name="sale_dealer_discount_product_id" class="oe_inline"/>
|
||||
</div>
|
||||
<div class="mt16 row">
|
||||
<label for="invoice_dealer_discount_product_id" class="col-xs-3 col-md-3 o_light_label"/>
|
||||
<field name="invoice_dealer_discount_product_id" class="oe_inline"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- Sale View -->
|
||||
<record id="view_order_form" model="ir.ui.view">
|
||||
<field name="name">sale.order.form.dealer_discount</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//field[@name='payment_term_id']" position="after">
|
||||
<label for="dealer_discount" attrs="{'invisible': [('state','!=', 'draft'),('state','!=', 'sent')]}"/>
|
||||
<div name='dealer_discount'>
|
||||
<div>
|
||||
<field name='dealer_discount' class="oe_inline" nolabel="1" attrs="{'invisible': [('state','!=', 'draft'),('state','!=', 'sent')]}"/>
|
||||
<field name='dealer_discount_type' class="oe_inline" nolabel="1" attrs="{'invisible': ['|',('dealer_discount','=', False),'&', ('state','!=', 'draft'),('state','!=', 'sent')], 'required':[('dealer_discount','!=', False)]}"/>
|
||||
<field name='dealer_discount_amount' class="oe_inline" nolabel="1" attrs="{'invisible': ['|','|',('dealer_discount','=', False),('dealer_discount_type','!=','fixed'),'&', ('state','!=', 'draft'),('state','!=', 'sent')]}"/>
|
||||
<field name='dealer_discount_percentage' class="oe_inline" nolabel="1" attrs="{'invisible': ['|','|',('dealer_discount','=', False),('dealer_discount_type','!=','percentage'),'&', ('state','!=', 'draft'),('state','!=', 'sent')]}"/>
|
||||
<button name="create_dealer_discount" string="Add Line" type="object" class="oe_inline fa fa-arrow-right oe_link oe_edit_only" attrs="{'invisible': ['|',('state','not in', ['draft','sent']),('dealer_discount','=', False)]}"/>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue