-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from farosinv/10.0
10.0
- Loading branch information
Showing
10 changed files
with
283 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import models | ||
from . import models | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Faros Inversiones Ltda. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'Sale Global Discount', | ||
'description': """ | ||
Add global discount to sales flow""", | ||
'version': '10.0.1.0.0', | ||
'license': 'AGPL-3', | ||
'author': 'Faros Inversiones Ltda.', | ||
'website': 'www.farosinv.cl', | ||
'depends': [ | ||
'sale', | ||
'account', | ||
], | ||
'data': [ | ||
'views/invoice_global_discount.xml', | ||
'security/sale_order_discount.xml', | ||
'views/sale_order_discount.xml', | ||
], | ||
'demo': [ | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import models | ||
from . import sale_order_discount | ||
from . import invoice_global_discount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Faros Inversiones Ltda. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models, _ | ||
|
||
|
||
class Invoice_global_discount(models.Model): | ||
|
||
_description = 'Invoice global discount' | ||
_inherit = 'account.invoice' | ||
|
||
discount_type = fields.Selection( | ||
[('percent','Percentage'), | ||
('amount','Amount')], | ||
string = 'Discount Type', | ||
help = 'Select discount type', | ||
default = 'percent') | ||
discount_rate = fields.Float( string = 'Discount Rate', default = '0.0', store = True) | ||
|
||
amount_discount = fields.Monetary( string = 'Total Global Discount', compute='_compute_discount', store = True) | ||
|
||
|
||
@api.one | ||
@api.depends('discount_type','discount_rate','amount_total') | ||
def _compute_discount(self): | ||
|
||
mod_obj = self.env['ir.model.data'] | ||
amount_discount = 0.0 | ||
if self.discount_type == 'percent': | ||
amount_discount = self.amount_untaxed * self.discount_rate / 100 | ||
else: | ||
amount_discount = self.discount_rate | ||
|
||
self.amount_discount = amount_discount | ||
|
||
|
||
@api.one | ||
@api.depends('invoice_line_ids.price_subtotal', 'tax_line_ids.amount', 'currency_id', 'company_id') | ||
def _compute_amount(self): | ||
|
||
self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line_ids) | ||
self.amount_tax = sum(line.amount for line in self.tax_line_ids) | ||
amount_discount = amount_total = 0.0 | ||
if self.discount_type == 'percent': | ||
amount_discount = self.amount_untaxed * self.discount_rate / 100 | ||
else: | ||
amount_discount = self.discount_rate | ||
|
||
amount_total = self.amount_untaxed - amount_discount + self.amount_tax | ||
self.amount_total = amount_total | ||
|
||
amount_total_company_signed = amount_total | ||
amount_untaxed_signed = self.amount_untaxed | ||
if self.currency_id and self.currency_id != self.company_id.currency_id: | ||
amount_total_company_signed = self.currency_id.compute(self.amount_total, self.company_id.currency_id) | ||
amount_untaxed_signed = self.currency_id.compute(self.amount_untaxed, self.company_id.currency_id) | ||
sign = self.type in ['in_refund', 'out_refund'] and -1 or 1 | ||
self.amount_total_company_signed = amount_total_company_signed * sign | ||
self.amount_total_signed = self.amount_total * sign | ||
self.amount_untaxed_signed = amount_untaxed_signed * sign | ||
|
||
@api.one | ||
@api.depends( | ||
'state', 'currency_id', 'invoice_line_ids.price_subtotal', | ||
'move_id.line_ids.amount_residual', | ||
'move_id.line_ids.currency_id') | ||
def _compute_residual(self): | ||
residual = 0.0 | ||
residual_company_signed = 0.0 | ||
sign = self.type in ['in_refund', 'out_refund'] and -1 or 1 | ||
for line in self.sudo().move_id.line_ids: | ||
if line.account_id.internal_type in ('receivable', 'payable'): | ||
residual_company_signed += line.amount_residual | ||
if line.currency_id == self.currency_id: | ||
residual += line.amount_residual_currency if line.currency_id else line.amount_residual | ||
else: | ||
from_currency = (line.currency_id and line.currency_id.with_context(date=line.date)) or line.company_id.currency_id.with_context(date=line.date) | ||
residual += from_currency.compute(line.amount_residual, self.currency_id) | ||
self.residual_company_signed = abs(residual_company_signed) * sign - self.amount_discount | ||
self.residual_signed = abs(residual) * sign - self.amount_discount | ||
self.residual = abs(residual) - self.amount_discount | ||
digits_rounding_precision = self.currency_id.rounding | ||
if float_is_zero(self.residual, precision_rounding=digits_rounding_precision): | ||
self.reconciled = True | ||
else: | ||
self.reconciled = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Faros Inversiones Ltda. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models, _ | ||
|
||
|
||
class Sale_order_discount(models.Model): | ||
|
||
_description = 'Sale order global discount' | ||
_inherit = 'sale.order' | ||
|
||
discount_type = fields.Selection( | ||
[('percent','Percentage'), | ||
('amount','Amount')], | ||
string = 'Discount Type', | ||
help = 'Select discount type', | ||
default = 'percent') | ||
discount_rate = fields.Float( string = 'Discount Rate', default = '0.0', store = True) | ||
|
||
amount_discount = fields.Float( string = 'Total Global Discount', compute='_compute_discount', store = True) | ||
|
||
|
||
@api.one | ||
@api.depends('discount_type','discount_rate','amount_total') | ||
def _compute_discount(self): | ||
|
||
mod_obj = self.env['ir.model.data'] | ||
amount_discount = 0.0 | ||
if self.discount_type == 'percent': | ||
amount_discount = self.amount_untaxed * self.discount_rate / 100 | ||
else: | ||
amount_discount = self.discount_rate | ||
|
||
self.amount_discount = amount_discount | ||
|
||
|
||
|
||
@api.depends('order_line.price_total') | ||
@api.multi | ||
def _amount_all(self): | ||
""" | ||
Compute the total amounts of the SO. | ||
""" | ||
|
||
for order in self: | ||
amount_untaxed = amount_tax = amount_discount = 0.0 | ||
for line in order.order_line: | ||
amount_untaxed += line.price_subtotal | ||
amount_tax += line.price_tax | ||
if self.discount_type == 'percent': | ||
amount_discount = amount_untaxed * self.discount_rate / 100 | ||
else: | ||
amount_discount = self.discount_rate | ||
|
||
order.update({ | ||
'amount_untaxed': order.pricelist_id.currency_id.round(amount_untaxed), | ||
'amount_tax': order.pricelist_id.currency_id.round(amount_tax), | ||
'amount_discount': order.pricelist_id.currency_id.round(amount_discount), | ||
'amount_total': amount_untaxed - amount_discount + amount_tax, | ||
}) | ||
|
||
|
||
|
||
@api.model | ||
def _prepare_invoice(self): | ||
""" | ||
This method send the discount_type, discount_rate and amount_discount to the | ||
account.invoice model | ||
""" | ||
res = super(sale_order_discount, self)._prepare_invoice() | ||
res['discount_type'] = self.discount_type | ||
res['discount_rate'] = self.discount_rate | ||
|
||
return res | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2017 Faros Inversiones Ltda. | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
|
||
<odoo> | ||
<!-- | ||
<record model="ir.model.access" id="sale_order_discount_access_name"> | ||
<field name="name">sale_order_discount access name</field> | ||
<field name="model_id" ref="model_sale_order_discount"/> | ||
<field name="group_id" ref="base.group_user"/> | ||
<field name="perm_read" eval="1"/> | ||
<field name="perm_create" eval="0"/> | ||
<field name="perm_write" eval="0"/> | ||
<field name="perm_unlink" eval="0"/> | ||
</record> | ||
--> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2017 Faros Inversiones Ltda. | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
|
||
<odoo> | ||
|
||
<record model="ir.ui.view" id="sale_global_discount_invoice"> | ||
<field name="name">sale_global_discount_invoice.form</field> | ||
<field name="model">account.invoice</field> | ||
<field name="inherit_id" ref="account.invoice_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='invoice_line_ids']" position="after"> | ||
<group name="discount" col="2" colspan="2"> | ||
<field name="discount_type" onchange="compute_discount"/> | ||
<field name="discount_rate" onchange="compute_discount"/> | ||
</group> | ||
</xpath> | ||
<xpath expr="//field[@name='amount_tax']" position="before"> | ||
<field name="amount_discount" widget='monetary' options="{'currency_field': 'currency_id'}"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2017 Faros Inversiones Ltda. | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
|
||
<odoo> | ||
<record model="ir.ui.view" id="sale_global_discount_sale_order"> | ||
<field name="name">sale_global_discount.form</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//group[@name='sale_total']" position="before"> | ||
<group name="discount" class="oe_left" colspan="2" col="2"> | ||
<field name="discount_type" onchange="compute_discount"/> | ||
<field name="discount_rate" onchange="compute_discount"/> | ||
</group> | ||
</xpath> | ||
<xpath expr="//field[@name='amount_tax']" position="before"> | ||
<field name="amount_discount" widget='monetary' options="{'currency_field': 'currency_id'}"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<!-- | ||
<record model="ir.ui.view" id="sale_order_discount_form_view"> | ||
<field name="name">sale_order_discount.form (in sale_global_discount)</field> | ||
<field name="model">sale_order_discount</field> | ||
<field name="inherit_id" ref="TODO othermodule.form_view"/> | ||
<field name="arch" type="xml"> | ||
</field> | ||
</record> | ||
<record model="ir.ui.view" id="sale_order_discount_search_view"> | ||
<field name="name">sale_order_discount.search (in sale_global_discount)</field> | ||
<field name="model">sale_order_discount</field> | ||
<field name="inherit_id" ref="TODO othermodule.search_view"/> | ||
<field name="arch" type="xml"> | ||
</field> | ||
</record> | ||
<record model="ir.ui.view" id="sale_order_discount_tree_view"> | ||
<field name="name">sale_order_discount.tree (in sale_global_discount)</field> | ||
<field name="model">sale_order_discount</field> | ||
<field name="inherit_id" ref="TODO othermodule.tree_view"/> | ||
<field name="arch" type="xml"> | ||
</field> | ||
</record> | ||
--> | ||
</odoo> |