Skip to content

Commit

Permalink
Merge PR #97 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
github-grap-bot committed Oct 7, 2024
2 parents 34d6b7d + 6ce79d7 commit 17523e3
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 7 deletions.
2 changes: 1 addition & 1 deletion joint_buying_product/__manifest__.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).
{
"name": "Joint Buying - Products",
"version": "12.0.5.0.1",
"version": "12.0.6.0.0",
"category": "GRAP - Logistics",
"author": "GRAP",
"website": "https://github.com/grap/odoo-addons-logistics",
Expand Down
58 changes: 58 additions & 0 deletions joint_buying_product/migrations/12.0.6.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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).

import logging

from openupgradelib import openupgrade

_logger = logging.getLogger(__name__)


@openupgrade.migrate()
def migrate(env, version):
JointBuyingOrder = env["joint.buying.purchase.order"]

# Get null orders deposited or closed
# that still have a transport request related
openupgrade.logged_query(
env.cr,
"""
SELECT po.id
FROM joint_buying_transport_request tr
INNER JOIN joint_buying_purchase_order po
ON po.id = tr.order_id
WHERE po.state IN ('deposited', 'closed')
AND po.amount_untaxed = 0.0;
""",
)

order_ids = [x[0] for x in env.cr.fetchall()]

_logger.info(f"Unlink Transport Requests for orders {order_ids} ...")
JointBuyingOrder.browse(order_ids)._hook_state_changed()

# Get NOT null recent orders
# that don't have a transport request related
openupgrade.logged_query(
env.cr,
"""
SELECT
po.id,
po.create_date,
po.state,
po.amount_untaxed
FROM joint_buying_purchase_order po
WHERE po.id not in (
SELECT order_id from joint_buying_transport_request
WHERE order_id is not null
)
AND po.deposit_partner_id != po.delivery_partner_id
AND po.amount_untaxed > 0.0 AND po.deposit_date > '2024-01-01';
""",
)

order_ids = [x[0] for x in env.cr.fetchall()]

_logger.info(f"Create Transport Requests for orders {order_ids} ...")
JointBuyingOrder.browse(order_ids)._hook_state_changed()
1 change: 1 addition & 0 deletions joint_buying_product/models/joint_buying_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class JointBuyingPurchaseOrder(models.Model):
amount_untaxed = fields.Float(
string="Total Untaxed Amount",
compute="_compute_amount",
track_visibility=True,
store=True,
digits=dp.get_precision("Product Price"),
)
Expand Down
10 changes: 10 additions & 0 deletions joint_buying_product/models/joint_buying_purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,13 @@ def _get_report_tour_data(self):
"</span>"
),
}

def write(self, vals):
res = super().write(vals)
# if the related orders are closed (or deposited), and if user changed the quantity
# lately. (for exemple, view joint.buying.wizard.update.order.grouped), we should
# ensure that transport request are correctly created. (or deleted)
self.mapped("order_id").filtered(
lambda x: x.state in ["closed", "deposited"]
)._hook_state_changed()
return res
1 change: 1 addition & 0 deletions joint_buying_product/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
from . import test_tour_report
from . import test_request_invalidate
from . import test_joint_buying_transport_request_compute
from . import test_joint_buying_wizard_update_order_grouped
7 changes: 7 additions & 0 deletions joint_buying_product/tests/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ def setUp(self):
self.Order = self.env["joint.buying.purchase.order"]
self.OrderLine = self.env["joint.buying.purchase.order.line"]
self.JointBuyingWizardCreateOrder = self.env["joint.buying.wizard.create.order"]
self.JointBuyingWizardUpdateOrderGrouped = self.env[
"joint.buying.wizard.update.order.grouped"
]

self.company_ELD = self.env.ref("joint_buying_base.company_ELD")
self.company_CDA = self.env.ref("joint_buying_base.company_CDA")
self.company_CHE = self.env.ref("joint_buying_base.company_CHE")
self.company_3PP = self.env.ref("joint_buying_base.company_3PP")
self.company_LSE = self.env.ref("joint_buying_base.company_LSE")
self.company_1GG = self.env.ref("joint_buying_base.company_1GG")

self.salaison_devidal = self.JointBuyingResPartner.browse(
self.env.ref("joint_buying_base.supplier_salaison_devidal").id
Expand All @@ -56,6 +60,9 @@ def setUp(self):
self.product_LSE_patatoe_agila = self.env.ref(
"joint_buying_product.product_LSE_patatoe_agila"
)
self.grouped_order_ronzon_past = self.env.ref(
"joint_buying_product.grouped_order_ronzon_past"
)

def _create_order_grouped_salaison_devidal_by_wizard(self, user=False):
# Use Wizard to create grouped order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@

from odoo.tests import tagged

from odoo.addons.joint_buying_base.tests import (
test_joint_buying_transport_request_compute,
)
from .test_abstract import TestAbstract


@tagged("post_install", "-at_install")
class TestJointBuyingTransportRequest(
test_joint_buying_transport_request_compute.TestJointBuyingTransportRequest
):
class TestJointBuyingTransportRequest(TestAbstract):
def setUp(self):
super().setUp()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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.tests import tagged

from .test_abstract import TestAbstract


@tagged("post_install", "-at_install")
class TestJointBuyingWizardUpdateOrderGrouped(TestAbstract):
def setUp(self):
super().setUp()

def test_01_wizard_update_order_grouped(self):

wizard = self.JointBuyingWizardUpdateOrderGrouped.with_context(
active_id=self.grouped_order_ronzon_past.id
).create({})
wizard.show_all_orders = True
wizard.show_all_products = True
wizard.onchange_show_settings()

wizard.line_ids.write({"qty": 0})

self.assertEqual(
len(
self.grouped_order_ronzon_past.mapped("order_ids.transport_request_id")
),
0,
)

wizard.line_ids.write({"qty": 100})

self.assertEqual(
len(
self.grouped_order_ronzon_past.mapped("order_ids.transport_request_id")
),
len(
self.grouped_order_ronzon_past.mapped("order_ids").filtered(
lambda x: x.deposit_partner_id != x.delivery_partner_id
)
),
)

0 comments on commit 17523e3

Please sign in to comment.