-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] joint_buying_account : Add the wizard to generate commission in…
…voices
- Loading branch information
1 parent
912ec11
commit 75458dd
Showing
12 changed files
with
517 additions
and
0 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 +1,2 @@ | ||
from . import models | ||
from . import wizards |
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 +1,4 @@ | ||
from . import res_company | ||
from . import res_config_settings | ||
from . import product_product | ||
from . import joint_buying_purchase_order_grouped |
11 changes: 11 additions & 0 deletions
11
joint_buying_account/models/joint_buying_purchase_order_grouped.py
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,11 @@ | ||
# Copyright (C) 2024-Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class JointBuyingPurchaseOrderGrouped(models.Model): | ||
_inherit = "joint.buying.purchase.order.grouped" | ||
|
||
invoice_line_id = fields.Many2one(comodel_name="account.invoice.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,14 @@ | ||
# Copyright (C) 2024-Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
joint_buying_commission_product_id = fields.Many2one( | ||
comodel_name="product.product", | ||
name="Joint Buying Commission Product", | ||
) |
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,16 @@ | ||
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
joint_buying_commission_product_id = fields.Many2one( | ||
comodel_name="product.product", | ||
name="Joint Buying Commission Product", | ||
related="company_id.joint_buying_commission_product_id", | ||
readonly=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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
Glue module between 'Joint buying' modules and ``account`` module. | ||
|
||
* Allow to create invoicing for joint buying suppliers. | ||
|
||
* Compute correctly the price of the global product (based on the local database) | ||
for product that have B2C taxes. (tax included.) |
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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) | ||
@author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
--> | ||
<odoo> | ||
|
||
<record id="view_res_config_settings_form" model="ir.ui.view"> | ||
<field name="model">res.config.settings</field> | ||
<field name="inherit_id" ref="joint_buying_base.view_res_config_settings_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='joint_buying_auto_subscribe']/../.." position="after"> | ||
<div class="col-xs-12 col-md-6 o_setting_box"> | ||
<div class="o_setting_left_pane"/> | ||
<div class="o_setting_right_pane"> | ||
<label for="joint_buying_commission_product_id"/> | ||
<div class="text-muted">Set the product used to make commission invoices.</div> | ||
<field name="joint_buying_commission_product_id"/> | ||
</div> | ||
</div> | ||
</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,2 @@ | ||
from . import joint_buying_invoice_commission_wizard | ||
from . import joint_buying_invoice_commission_wizard_line |
94 changes: 94 additions & 0 deletions
94
joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py
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,94 @@ | ||
# Copyright (C) 2017 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from datetime import timedelta | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import Warning as UserError | ||
|
||
|
||
class JointBuyingInvoiceCommissionWizard(models.TransientModel): | ||
_name = "joint.buying.invoice.commission.wizard" | ||
_description = "Joint Buying Invoice Commission Wizard" | ||
|
||
# Columns Section | ||
max_deposit_date = fields.Date( | ||
string="Max Deposit Date", | ||
required=True, | ||
default=lambda x: x._default_max_deposit_date(), | ||
help="The commission will be computed for the grouped order" | ||
" deposited by the suppliers until this date included.", | ||
) | ||
|
||
wizard_line_ids = fields.One2many( | ||
comodel_name="joint.buying.invoice.commission.wizard.line", | ||
inverse_name="wizard_id", | ||
default=lambda x: x._default_wizard_line_ids(), | ||
) | ||
|
||
# Default values Section | ||
def _default_wizard_line_ids(self): | ||
res = [] | ||
ResPartner = self.env["res.partner"] | ||
WizardLine = self.env["joint.buying.invoice.commission.wizard.line"] | ||
partners = ResPartner.browse(self.env.context.get("active_ids", [])) | ||
for partner in partners: | ||
local_partner = partner.get_joint_buying_local_partner_id() | ||
line_vals = { | ||
"partner_id": partner.id, | ||
"local_partner_id": local_partner and local_partner.id, | ||
"commission_rate": partner.joint_buying_commission_rate, | ||
"grouped_order_qty": len( | ||
WizardLine._compute_grouped_order_ids_model( | ||
self._default_max_deposit_date(), partner | ||
) | ||
), | ||
} | ||
res.append([0, 0, line_vals]) | ||
return res | ||
|
||
def _default_max_deposit_date(self): | ||
today = fields.date.today() | ||
return fields.date(today.year, today.month, 1) - timedelta(days=1) | ||
|
||
# Action Section | ||
@api.multi | ||
def invoice_commission(self): | ||
self.ensure_one() | ||
self._check_values() | ||
invoices = self.env["account.invoice"] | ||
|
||
for wizard_line in self.wizard_line_ids.filtered(lambda x: x.grouped_order_qty): | ||
invoice = wizard_line._create_invoice() | ||
invoices |= invoice | ||
|
||
if not invoices: | ||
raise UserError( | ||
_( | ||
"No Grouped Order to invoice for the" | ||
" selected suppliers and the selected date." | ||
) | ||
) | ||
|
||
# Recompute Taxes | ||
invoices.compute_taxes() | ||
|
||
action = self.env.ref("account.action_invoice_tree1").read()[0] | ||
|
||
if len(invoices) > 1: | ||
action["domain"] = ( | ||
"[('id', 'in', [" + ",".join(map(str, invoices.ids)) + "])]" | ||
) | ||
else: | ||
form_view = [(self.env.ref("account.invoice_form").id, "form")] | ||
action["views"] = form_view + [ | ||
(state, view) | ||
for state, view in action.get("views", []) | ||
if view != "form" | ||
] | ||
action["res_id"] = invoices.ids[0] | ||
|
||
return action | ||
|
||
def _check_values(self): | ||
self.mapped("wizard_line_ids")._check_values() | ||
Oops, something went wrong.