Skip to content

Commit

Permalink
[ADD] joint_buying_account : Add the wizard to generate commission in…
Browse files Browse the repository at this point in the history
…voices
  • Loading branch information
legalsylvain committed Feb 2, 2024
1 parent 912ec11 commit 75458dd
Show file tree
Hide file tree
Showing 12 changed files with 517 additions and 0 deletions.
1 change: 1 addition & 0 deletions joint_buying_account/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import wizards
4 changes: 4 additions & 0 deletions joint_buying_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"demo/account_tax.xml",
"demo/product_product.xml",
],
"data": [
"wizards/view_joint_buying_invoice_commission_wizard.xml",
"views/view_res_config_settings.xml",
],
"installable": True,
"auto_install": True,
}
3 changes: 3 additions & 0 deletions joint_buying_account/models/__init__.py
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 joint_buying_account/models/joint_buying_purchase_order_grouped.py
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")
14 changes: 14 additions & 0 deletions joint_buying_account/models/res_company.py
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",
)
16 changes: 16 additions & 0 deletions joint_buying_account/models/res_config_settings.py
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,
)
2 changes: 2 additions & 0 deletions joint_buying_account/readme/DESCRIPTION.rst
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.)
26 changes: 26 additions & 0 deletions joint_buying_account/views/view_res_config_settings.xml
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>
2 changes: 2 additions & 0 deletions joint_buying_account/wizards/__init__.py
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
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", []))

Check warning on line 34 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L31-L34

Added lines #L31 - L34 were not covered by tests
for partner in partners:
local_partner = partner.get_joint_buying_local_partner_id()
line_vals = {

Check warning on line 37 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L36-L37

Added lines #L36 - L37 were not covered by tests
"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

Check warning on line 48 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L47-L48

Added lines #L47 - L48 were not covered by tests

def _default_max_deposit_date(self):
today = fields.date.today()
return fields.date(today.year, today.month, 1) - timedelta(days=1)

Check warning on line 52 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L51-L52

Added lines #L51 - L52 were not covered by tests

# Action Section
@api.multi
def invoice_commission(self):
self.ensure_one()
self._check_values()
invoices = self.env["account.invoice"]

Check warning on line 59 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L57-L59

Added lines #L57 - L59 were not covered by tests

for wizard_line in self.wizard_line_ids.filtered(lambda x: x.grouped_order_qty):
invoice = wizard_line._create_invoice()
invoices |= invoice

Check warning on line 63 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L62-L63

Added lines #L62 - L63 were not covered by tests

if not invoices:
raise UserError(

Check warning on line 66 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L66

Added line #L66 was not covered by tests
_(
"No Grouped Order to invoice for the"
" selected suppliers and the selected date."
)
)

# Recompute Taxes
invoices.compute_taxes()

Check warning on line 74 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L74

Added line #L74 was not covered by tests

action = self.env.ref("account.action_invoice_tree1").read()[0]

Check warning on line 76 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L76

Added line #L76 was not covered by tests

if len(invoices) > 1:
action["domain"] = (

Check warning on line 79 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L79

Added line #L79 was not covered by tests
"[('id', 'in', [" + ",".join(map(str, invoices.ids)) + "])]"
)
else:
form_view = [(self.env.ref("account.invoice_form").id, "form")]

Check warning on line 83 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L83

Added line #L83 was not covered by tests
action["views"] = form_view + [
(state, view)
for state, view in action.get("views", [])
if view != "form"
]
action["res_id"] = invoices.ids[0]

Check warning on line 89 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L89

Added line #L89 was not covered by tests

return action

Check warning on line 91 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L91

Added line #L91 was not covered by tests

def _check_values(self):
self.mapped("wizard_line_ids")._check_values()

Check warning on line 94 in joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_account/wizards/joint_buying_invoice_commission_wizard.py#L94

Added line #L94 was not covered by tests
Loading

0 comments on commit 75458dd

Please sign in to comment.