Skip to content

Commit

Permalink
[REF] recurring_consignment_pos: Migration to V16:
Browse files Browse the repository at this point in the history
- no need to use anymore constrains to prevent sale to customer in Point of sale
- Add test
- add constrains to avoid to change a consignor setting, if a PoS session is opened because incorrect taxes configuration should be loaded and then generate bad account move.

[FIX] recurring_consignment:
- Fix bad lines in commission report, for account move lines that are generated by PoS
  • Loading branch information
legalsylvain committed Jun 27, 2024
1 parent 9c98971 commit 0839aaf
Show file tree
Hide file tree
Showing 21 changed files with 394 additions and 143 deletions.
28 changes: 28 additions & 0 deletions recurring_consignment/demo/account_account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>

<!-- oca-hooks: disable=xml-duplicate-record-id -->


<record id="account_receivable" model="account.account">
<field name="name">Demo Account Receivable</field>
<field name="code">411</field>
Expand Down Expand Up @@ -38,6 +41,27 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="company_id" ref="company" />
</record>

<record id="account_cash_suspense_account" model="account.account">
<field name="name">Cash Suspense Account</field>
<field name="code">5xx</field>
<field name="account_type">asset_current</field>
<field name="company_id" ref="company" />
</record>

<record id="account_expense_extra" model="account.account">
<field name="name">Extra Expense</field>
<field name="code">658</field>
<field name="account_type">expense</field>
<field name="company_id" ref="company" />
</record>

<record id="account_income_extra" model="account.account">
<field name="name">Extra Revenue</field>
<field name="code">758</field>
<field name="account_type">income</field>
<field name="company_id" ref="company" />
</record>

<record id="account_income_commission" model="account.account">
<field name="name">Commission Account</field>
<field name="code">706</field>
Expand All @@ -52,4 +76,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="company_id" ref="company" />
</record>

<record id="company" model="res.company">
<field name="account_default_pos_receivable_account_id" ref="account_receivable"/>
</record>

</odoo>
20 changes: 16 additions & 4 deletions recurring_consignment/demo/account_journal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@ Copyright (C) 2015 - 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>
<odoo noupdate="1">

<!-- oca-hooks: disable=xml-duplicate-record-id -->

<record id="account_journal_sale" model="account.journal">
<field name="name">Demo Sale Journal For Consignor</field>
<field name="name">Demo Sale Journal</field>
<field name="type">sale</field>
<field name="code">SJ-CONS</field>
<field name="code">SALE</field>
<field name="company_id" ref="company" />
</record>

<record id="account_journal_cash" model="account.journal">
<field name="name">Demo Cash Journal</field>
<field name="type">cash</field>
<field name="code">CASH</field>
<field name="company_id" ref="company" />
<field name="suspense_account_id" ref="account_cash_suspense_account" />
<field name="loss_account_id" ref="account_expense_extra" />
<field name="profit_account_id" ref="account_income_extra" />
</record>


<record id="account_journal_misc" model="account.journal">
<field name="name">Demo Misc Journal For Consignor</field>
<field name="type">general</field>
<field name="code">MC-CONS</field>
<field name="code">MISC</field>
<field name="company_id" ref="company" />
</record>

Expand Down
6 changes: 4 additions & 2 deletions recurring_consignment/demo/product_pricelist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

<record id="sale_pricelist_10" model="product.pricelist">
<field name="name">My Pricelist (-10%)</field>
<field name="currency_id" ref="base.USD" />
<field name="company_id" ref="company"/>
<field name="currency_id" ref="base.EUR" />
</record>

<record id="sale_pricelist_item_10" model="product.pricelist.item">
Expand All @@ -21,7 +22,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

<record id="sale_pricelist_50" model="product.pricelist">
<field name="name">My Pricelist (-50%)</field>
<field name="currency_id" ref="base.USD" />
<field name="company_id" ref="company"/>
<field name="currency_id" ref="base.EUR" />
<field name="consignment_pricelist_id" ref="sale_pricelist_10"/>
</record>

Expand Down
2 changes: 1 addition & 1 deletion recurring_consignment/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _get_commission_information_product_detail_grouped(self):
# Get related invoice lines
com_invoice_lines = self.mapped(
"invoice_line_ids.consignment_invoice_line_ids"
).filtered(lambda x: x.display_type == "product")
).filtered(lambda x: x.display_type == "product" and x.product_id)

for com_invoice_line in com_invoice_lines:
key = (
Expand Down
16 changes: 2 additions & 14 deletions recurring_consignment/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import Warning as UserError
from odoo.exceptions import UserError


class ResPartner(models.Model):
Expand Down Expand Up @@ -35,7 +35,7 @@ def _check_is_consignor_consignment_account_id(self):
if partner.is_consignor:
if not partner.consignment_account_id:
raise UserError(
_("A Consignor must have a 'Consignment Account'" " defined.")
_("A Consignor must have a 'Consignment Account' defined.")
)
else:
if (
Expand All @@ -48,15 +48,3 @@ def _check_is_consignor_consignment_account_id(self):
" Commission' neither 'Consignment Account' defined."
)
)

# TODO prevent check and uncheck. (only via wizard is possible)
# # Overload Section
# def write(self, vals):
# if not vals.get("is_consignor", True) and any(self.mapped("is_consignor")):
# raise UserError(
# _(
# "You can not unset consignor setting on partner.\n"
# " Please create a new one if you want to do so."
# )
# )
# return super().write(vals)
6 changes: 3 additions & 3 deletions recurring_consignment/tests/test_make_commissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@tagged("post_install", "-at_install")
class TestCreateConsignors(TransactionCase):
class TestMakeCommissions(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -73,13 +73,13 @@ def test_30_commission_workflow(self):
self.assertEqual(
len(commission_invoice.invoice_line_ids),
1,
"Two commission lines should be generated",
"One commission line should be generated",
)
self.assertEqual(
len(lines_20), 1, "One 20% commission line should be generated"
)

# Check line #2 details (Tax Excl)
# Check line details (Tax Excl)
line_20 = lines_20[0]
self.assertEqual(line_20.quantity, 1, "Incorrect Commission Quantity.")
self.assertEqual(
Expand Down
12 changes: 8 additions & 4 deletions recurring_consignment_pos/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
"website": "https://github.com/grap/grap-odoo-business",
"license": "AGPL-3",
"depends": [
"recurring_consignment",
# Odoo
"point_of_sale",
# GRAP
"recurring_consignment",
],
"data": [
"views/view_account_invoice.xml",
"views/templates.xml",
"data": ["views/view_account_move.xml"],
"demo": [
"demo/pos_payment_method.xml",
"demo/pos_config.xml",
"demo/product_product.xml",
],
"installable": True,
"auto_install": True,
Expand Down
19 changes: 19 additions & 0 deletions recurring_consignment_pos/demo/pos_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2015 - 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="pos_config" model="pos.config">
<field name="name">Pos Config</field>
<field name="company_id" ref="recurring_consignment.company" />
<field name="journal_id" ref="recurring_consignment.account_journal_sale" />
<field name="picking_type_id" model="stock.picking.type" search="[('company_id', '=', ref('recurring_consignment.company')), ('code', '=', 'outgoing'), ('sequence_code', '=', 'POS')]" />
<field name="invoice_journal_id" ref="recurring_consignment.account_journal_sale" />
<field name="payment_method_ids" eval="[(4, ref('recurring_consignment_pos.payment_method_cash'))]" />
<field name="available_pricelist_ids" eval="[(4, ref('recurring_consignment.sale_pricelist_10'))]" />
</record>

</odoo>
15 changes: 15 additions & 0 deletions recurring_consignment_pos/demo/pos_payment_method.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2015 - 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="payment_method_cash" model="pos.payment.method">
<field name="name">Cash Method</field>
<field name="journal_id" ref="recurring_consignment.account_journal_cash" />
<field name="company_id" ref="recurring_consignment.company" />
</record>

</odoo>
34 changes: 34 additions & 0 deletions recurring_consignment_pos/demo/product_product.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2015 - 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="recurring_consignment.consigned_product_consignor_1_vat_5_A" model="product.product">
<field name="available_in_pos" eval="True"/>
</record>

<record id="recurring_consignment.consigned_product_consignor_1_vat_5_B" model="product.product">
<field name="available_in_pos" eval="True"/>
</record>

<record id="recurring_consignment.consigned_product_consignor_1_vat_20_C" model="product.product">
<field name="available_in_pos" eval="True"/>
</record>

<record id="recurring_consignment.consigned_product_consignor_1_vat_20_D" model="product.product">
<field name="available_in_pos" eval="True"/>
</record>

<record id="consigned_product_consignor_1_vat_20_E" model="product.product">
<field name="name">My Consigned Product E (VAT 20% - Consignor 1)</field>
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="consignor_partner_id" ref="recurring_consignment.consignor_1"/>
<field name="fiscal_classification_id" ref="recurring_consignment.fiscal_classification_20_consignor_1"/>
<field name="available_in_pos" eval="True"/>
</record>

</odoo>
3 changes: 1 addition & 2 deletions recurring_consignment_pos/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import account_invoice
from . import pos_order
from . import account_move
from . import product_template
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models
from odoo import models


class AccountInvoice(models.Model):
_inherit = "account.invoice"
class AccountMove(models.Model):
_inherit = "account.move"

# View Section
def button_commission_view_pos_order_lines(self):
Expand All @@ -17,21 +17,40 @@ def button_commission_view_pos_order_lines(self):
return action_data

# Private Section
def _get_commission_information_product_detail_grouped(self):
groups = super()._get_commission_information_product_detail_grouped()

# Get related pos order lines
com_order_lines = self._get_commission_related_pos_order_lines()
for com_order_line in com_order_lines:
key = (
com_order_line.product_id,
com_order_line.price_unit,
com_order_line.discount,
)
groups.setdefault(key, {"quantity": 0, "total_vat_excl": 0})
groups[key] = {
"quantity": groups[key]["quantity"] + com_order_line.qty,
"total_vat_excl": groups[key]["total_vat_excl"]
+ com_order_line.price_subtotal,
}
return groups

def _get_commission_related_pos_order_lines(self):
PosOrder = self.env["pos.order"]
PosOrderLine = self.env["pos.order.line"]
ProductProduct = self.env["product.product"]

# Get Account Move
moves = self.mapped("consignment_line_ids.move_id")
moves = self.mapped("invoice_line_ids.consignment_invoice_line_ids.move_id")

# Get Product ids
consignor_products = ProductProduct.with_context(active_test=False).search(
[("consignor_partner_id", "in", self.mapped("partner_id").ids)]
)

# Get related pos orders
com_orders = PosOrder.search([("account_move", "in", moves.ids)])
com_orders = PosOrder.search([("session_move_id", "in", moves.ids)])

# We add pos.order.line sales, that are not invoiced
# because the lines are still include in the module
Expand All @@ -44,29 +63,3 @@ def _get_commission_related_pos_order_lines(self):
("product_id", "in", consignor_products.ids),
]
)

def _get_commission_information_product_detail_grouped(self):
groups = super().get_commission_information_product_detail_grouped()

# Get related pos order lines
com_order_lines = self._get_commission_related_pos_order_lines()

for com_order_line in com_order_lines:
key = (
com_order_line.product_id.id,
com_order_line.price_unit,
com_order_line.discount,
)
groups.setdefault(
key,
{
"quantity": 0,
"total_vat_excl": 0,
},
)
groups[key] = {
"quantity": groups[key]["quantity"] + com_order_line.qty,
"total_vat_excl": groups[key]["total_vat_excl"]
+ com_order_line.price_subtotal,
}
return groups
15 changes: 0 additions & 15 deletions recurring_consignment_pos/models/pos_order.py

This file was deleted.

Loading

0 comments on commit 0839aaf

Please sign in to comment.