Skip to content

Commit

Permalink
F : add request_type : 'sale'
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Nov 28, 2023
1 parent bb9b888 commit cd09aea
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 17 deletions.
12 changes: 6 additions & 6 deletions joint_buying_product/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from . import test_abstract

# from . import test_joint_buying_purchase_order
# from . import test_joint_buying_transport_request
# from . import test_product
# from . import test_check_access_product
# from . import test_check_access_joint_buying_purchase
# from . import test_tour_report
from . import test_joint_buying_purchase_order
from . import test_joint_buying_transport_request
from . import test_product
from . import test_check_access_product
from . import test_check_access_joint_buying_purchase
from . import test_tour_report

from . import test_joint_buying_transport_request_compute
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def test_create_transport_request_joint_buying(self):
request = order_VEV.transport_request_id

# Check that transport request is created
self.assertTrue(order_VEV.transport_request_id)
self.assertTrue(request)
self.assertEqual(request.request_type, "joint_buying")

# Check can change values
self.assertFalse(request.can_change_date)
Expand Down
6 changes: 3 additions & 3 deletions joint_buying_product/tests/test_tour_report.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
# Copyright (C) 2023 - 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 odoo.addons.joint_buying_base.tests.test_tour_report import TestTourReportBase
from odoo.addons.joint_buying_base.tests import test_tour_report


@tagged("post_install", "-at_install")
class TestTourReportProduct(TestTourReportBase):
class TestTourReportSale(test_tour_report.TestTourReportBase):
pass
4 changes: 2 additions & 2 deletions joint_buying_product_food/tests/test_tour_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

from odoo.tests import tagged

from odoo.addons.joint_buying_product.tests.test_tour_report import TestTourReportBase
from odoo.addons.joint_buying_base.tests import test_tour_report


@tagged("post_install", "-at_install")
class TestTourReportProductFood(TestTourReportBase):
class TestTourReportProduct(test_tour_report.TestTourReportBase):
pass
2 changes: 1 addition & 1 deletion joint_buying_sale/demo/joint_buying_transport_request.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<odoo>

<record id="request_lse_cda_week_0" model="joint.buying.transport.request">
<field name="sale_order_id" ref="sale_order_1"/>
<field name="manual_origin_partner_id" model="res.partner" eval="obj().env.ref('joint_buying_base.company_LSE').joint_buying_partner_id.id"/>
<field name="manual_destination_partner_id" model="res.partner" eval="obj().env.ref('joint_buying_base.company_CDA').joint_buying_partner_id.id"/>
<field name="manual_start_date" eval="(DateTime.today() + timedelta(days=-15)).strftime('%Y-%m-%d 07:00')"/>
<field name="sale_order_id" ref="sale_order_1" />
</record>

</odoo>
3 changes: 3 additions & 0 deletions joint_buying_sale/demo/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="uom.product_uom_unit"/>
<field name="price_unit">12.00</field>
<field name="unit_weight">0.210</field>
</record>

<!-- Second Sale Order-->
Expand All @@ -55,6 +56,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="product_uom_qty">20</field>
<field name="product_uom" ref="uom.product_uom_unit"/>
<field name="price_unit">15.00</field>
<field name="unit_weight">0.210</field>
</record>

<record id="sale_order_2_line_2" model="sale.order.line">
Expand All @@ -64,6 +66,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="product_uom_qty">30</field>
<field name="product_uom" ref="uom.product_uom_unit"/>
<field name="price_unit">12.00</field>
<field name="unit_weight">0.210</field>
</record>

</odoo>
34 changes: 32 additions & 2 deletions joint_buying_sale/models/joint_buying_transport_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@
class JointBuyingTransportRequest(models.Model):
_inherit = "joint.buying.transport.request"

request_type = fields.Selection(selection_add=[("sale", "Sale Order")])

sale_order_id = fields.Many2one(
comodel_name="sale.order",
readonly=True,
help="Sale order in the local database of the"
" company that requires transport.",
ondelete="cascade",
)

def _get_depends_request_type(self):
res = super()._get_depends_request_type()
res.append("sale_order_id")
return res

def _get_depends_amount_untaxed(self):
res = super()._get_depends_amount_untaxed()
res.append("sale_order_id.amount_untaxed")
Expand All @@ -30,11 +36,19 @@ def _get_depends_description(self):
res = super()._get_depends_description()
res += [
"sale_order_id.order_line.product_id",
"sale_order_id.order_line.product_uom",
"sale_order_id.order_line.product_uom_qty",
"sale_order_id.order_line.product_uom.name",
]
return res

def _compute_request_type(self):
super(
JointBuyingTransportRequest, self.filtered(lambda x: not x.sale_order_id)
)._compute_request_type()

for request in self.filtered(lambda x: x.sale_order_id):
request.request_type = "sale"

def _compute_amount_untaxed(self):
super(
JointBuyingTransportRequest, self.filtered(lambda x: not x.sale_order_id)
Expand All @@ -51,6 +65,22 @@ def _compute_total_weight(self):
for request in self.filtered(lambda x: x.sale_order_id):
request.total_weight = request.sale_order_id.total_ordered_weight

def _compute_description(self):
super(
JointBuyingTransportRequest, self.filtered(lambda x: not x.sale_order_id)
)._compute_description()

for request in self.filtered(lambda x: x.sale_order_id):
description = ""
for line in request.sale_order_id.order_line:
description += (
f"{line.product_id.name}"
"<span style='color:#888;'>"
f" ({line.product_uom_qty} x {line.product_uom.name}) "
"</span>"
)
request.description = description

def _compute_can_change(self):
super(
JointBuyingTransportRequest, self.filtered(lambda x: not x.sale_order_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
# Copyright (C) 2023 - 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).

Expand All @@ -15,4 +15,42 @@ class TestJointBuyingTransportRequest(
test_joint_buying_transport_request_compute.TestJointBuyingTransportRequest
):
def test_create_transport_request_sale(self):
pass
sale_order = self.env.ref("joint_buying_sale.sale_order_1")
sale_order_line = self.env.ref("joint_buying_sale.sale_order_1_line_1")
request = sale_order.joint_buying_transport_request_id

# Check that transport request is created
self.assertTrue(request)
self.assertEqual(request.request_type, "sale")

# Check can change values
self.assertTrue(request.can_change_date)
self.assertFalse(request.can_change_extra_data)
self.assertTrue(request.can_change_partners)

# Check computation
first_description = request.description
first_amount_untaxed = request.amount_untaxed
first_total_weight = request.total_weight

# (The order contains Agila x 80 and Charlotte x 60)
self.assertIn("(3", first_description)
self.assertNotIn("(2222", first_description)

self.assertEqual(first_amount_untaxed, sale_order.amount_untaxed)

# self.assertEqual(first_total_weight, sale_order.xxx)

# Change value of order line qty and check recomputation
sale_order_line.product_uom_qty = 2222

self.assertNotEqual(first_amount_untaxed, request.description)
self.assertNotIn("(3", request.description)
self.assertIn("(2222", request.description)

self.assertNotEqual(first_amount_untaxed, request.amount_untaxed)
self.assertEqual(request.amount_untaxed, sale_order.amount_untaxed)

first_total_weight = first_total_weight
# self.assertNotEqual(first_total_weight, request.total_weight)
# self.assertEqual(request.total_weight, sale_order.total_weight)

0 comments on commit cd09aea

Please sign in to comment.