-
-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] purchase_triple_discount: Migration to 11.0
- Loading branch information
1 parent
2db596a
commit 82b7883
Showing
19 changed files
with
816 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
account-invoicing | ||
server-tools | ||
product-attribute | ||
server-ux | ||
|
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 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
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 |
---|---|---|
@@ -1,21 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
'name': 'Account Invoice Triple Discount', | ||
'version': '10.0.1.1.0', | ||
'version': '11.0.1.0.0', | ||
'category': 'Purchase Management', | ||
'author': 'Tecnativa, ' | ||
'Odoo Community Association (OCA)', | ||
'website': 'https://tecnativa.com', | ||
'website': 'https://github.com/OCA/purchase-workflow', | ||
'license': 'AGPL-3', | ||
'summary': 'Manage triple discount on purchase order lines', | ||
'depends': [ | ||
'purchase_discount', | ||
'product_supplierinfo_discount', | ||
'account_invoice_triple_discount', | ||
], | ||
'data': [ | ||
'views/product_supplierinfo_view.xml', | ||
'views/purchase_view.xml', | ||
'views/res_partner_view.xml', | ||
], | ||
'installable': True, | ||
} |
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,4 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import account_invoice | ||
from . import procurement_rule | ||
from . import product_supplierinfo | ||
from . import purchase_order | ||
from . import res_partner |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2019 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class ProcurementRule(models.Model): | ||
_inherit = 'procurement.rule' | ||
|
||
def _prepare_purchase_order_line(self, product_id, product_qty, | ||
product_uom, values, po, supplier): | ||
"""Apply the discount to the created purchase order""" | ||
res = super(ProcurementRule, self)._prepare_purchase_order_line( | ||
product_id, product_qty, product_uom, values, po, supplier) | ||
date = None | ||
if po.date_order: | ||
date = fields.Date.to_string( | ||
fields.Date.from_string(po.date_order)) | ||
seller = product_id._select_seller( | ||
partner_id=supplier.name, | ||
quantity=product_qty, | ||
date=date, uom_id=product_uom) | ||
if seller: | ||
res['discount2'] = seller.discount2 | ||
res['discount3'] = seller.discount3 | ||
return res |
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,43 @@ | ||
# Copyright 2019 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import models, fields, api | ||
import odoo.addons.decimal_precision as dp | ||
|
||
|
||
class ProductSupplierInfo(models.Model): | ||
_inherit = 'product.supplierinfo' | ||
|
||
discount2 = fields.Float( | ||
string='Discount 2 (%)', | ||
digits=dp.get_precision('Discount'), | ||
) | ||
discount3 = fields.Float( | ||
string='Discount 3 (%)', | ||
digits=dp.get_precision('Discount'), | ||
) | ||
|
||
@api.onchange('name') | ||
def onchange_name(self): | ||
"""Apply the default supplier discounts of the selected supplier""" | ||
for supplierinfo in self.filtered('name'): | ||
supplierinfo.discount2 = ( | ||
supplierinfo.name.default_supplierinfo_discount2) | ||
supplierinfo.discount3 = ( | ||
supplierinfo.name.default_supplierinfo_discount3) | ||
return super().onchange_name() | ||
|
||
@api.model | ||
def create(self, vals): | ||
"""Insert discounts 2 and 3 from context from purchase.order's | ||
_add_supplier_to_product method""" | ||
if ('discount2_map' in self.env.context and | ||
not vals.get('discount2') and | ||
vals['product_tmpl_id'] in self.env.context['discount2_map']): | ||
vals['discount2'] = self.env.context['discount2_map'][ | ||
vals['product_tmpl_id']] | ||
if ('discount3_map' in self.env.context and | ||
not vals.get('discount3') and | ||
vals['product_tmpl_id'] in self.env.context['discount3_map']): | ||
vals['discount3'] = self.env.context['discount3_map'][ | ||
vals['product_tmpl_id']] | ||
return super(ProductSupplierInfo, self).create(vals) |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2019 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import models, fields | ||
from odoo.addons import decimal_precision as dp | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
default_supplierinfo_discount2 = fields.Float( | ||
string='Default Supplier Discount 2 (%)', | ||
digits=dp.get_precision('Discount'), | ||
help="This value will be used as the default one, for each new " | ||
"supplierinfo line depending on that supplier.", | ||
) | ||
default_supplierinfo_discount3 = fields.Float( | ||
string='Default Supplier Discount 3 (%)', | ||
digits=dp.get_precision('Discount'), | ||
help="This value will be used as the default one, for each new " | ||
"supplierinfo line depending on that supplier.", | ||
) |
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,3 @@ | ||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* David Vidal |
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,2 @@ | ||
This module allows to have three successive discounts on every purchase order | ||
line. |
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 @@ | ||
* Include second and third discount in purchase order report. |
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 @@ | ||
Create a new purchase order and add discounts in any of the three discount | ||
fields given. They go in order of precedence so discount 2 will be calculated | ||
over discount 1 and discount 3 over the result of discount 2. For example, | ||
let's divide by two on every discount: | ||
|
||
Unit price: 600.00 -> | ||
|
||
- Disc. 1 = 50% -> Amount = 300.00 | ||
- Disc. 2 = 50% -> Amount = 150.00 | ||
- Disc. 3 = 50% -> Amount = 75.00 | ||
|
||
You can also use negative values to charge instead of discount: | ||
|
||
Unit price: 600.00 -> | ||
|
||
- Disc. 1 = 50% -> Amount = 300.00 | ||
- Disc. 2 = -5% -> Amount = 315.00 | ||
|
||
* When the purchase order is validated, the discounts will be added to the | ||
corresponding vendor pricelist. | ||
* Vendor pricelists can be edited as well with their corresponding new second | ||
and third discounts. | ||
* A default second or third discount can be set in every vendor | ||
*Sale & Purchases* tab. |
Oops, something went wrong.