Skip to content

Commit

Permalink
wip on finit ce projet, là !
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Nov 27, 2023
1 parent 9611c92 commit 51e38e1
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 40 deletions.
1 change: 1 addition & 0 deletions joint_buying_base/models/joint_buying_transport_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class JointBuyingTransportRequest(models.Model):
compute="_compute_weight",
store=True,
digits=dp.get_precision("Stock Weight"),
compute_sudo=True,
)

line_ids = fields.One2many(
Expand Down
2 changes: 2 additions & 0 deletions joint_buying_base/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
from . import test_joint_buying_wizard_find_route
from . import test_tour
from . import test_tour_report

from . import test_joint_buying_transport_request
8 changes: 8 additions & 0 deletions joint_buying_base/tests/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def setUp(self):
mail_create_nosubscribe=True
)

self.user_3PP = self.env.ref("joint_buying_base.user_joint_buying_user_3PP")

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

# Custom Functions
def _create_supplier(self, user=False, extra_vals=False):
if not user:
Expand Down
1 change: 0 additions & 1 deletion joint_buying_base/tests/test_company_2_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
class TestModule(TestAbstract):
def setUp(self):
super().setUp()
self.company_3PP = self.env.ref("joint_buying_base.company_3PP")
self.ResCompany = self.env["res.company"]
self.suffixParameter = self.env.ref("joint_buying_base.parameter_group_name")

Expand Down
1 change: 0 additions & 1 deletion joint_buying_base/tests/test_joint_buying_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
class TestModule(TestAbstract):
def setUp(self):
super().setUp()
self.user_3PP = self.env.ref("joint_buying_base.user_joint_buying_user_3PP")
self.joint_buying_supplier = self.env.ref(
"joint_buying_base.supplier_fumet_dombes"
)
Expand Down
41 changes: 41 additions & 0 deletions joint_buying_base/tests/test_joint_buying_transport_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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).

from datetime import datetime

from odoo.tests import tagged

from .test_abstract import TestAbstract


@tagged("post_install", "-at_install")
class TestJointBuyingTransportRequest(TestAbstract):
def setUp(self):
super().setUp()
self.TransportRequest = self.env["joint.buying.transport.request"]

def test_create_transport_request_manual(self):
request = self.TransportRequest.create(
{
"manual_origin_partner_id": self.company_CDA.joint_buying_partner_id.id,
"manual_destination_partner_id": self.company_CHE.joint_buying_partner_id.id,
"manual_description": "manual_description",
"manual_start_date": datetime.today(),
"manual_amount_untaxed": 999,
"manual_total_weight": 111,
}
)

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

# Check computation
request.manual_description = "bob"
self.assertEqual(request.description, "<p>bob</p>")
request.manual_amount_untaxed = 888
self.assertEqual(request.amount_untaxed, 888)
request.manual_total_weight = 222
self.assertEqual(request.total_weight, 222)
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

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

def test_20_transport_request_vev_cda_week_1(self):
"""simplest case: direct route"""
self._verify_tour_lines_computation(
Expand Down
5 changes: 0 additions & 5 deletions joint_buying_base/tests/test_partner_global_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

@tagged("post_install", "-at_install")
class TestModule(TestAbstract):
def setUp(self):
super().setUp()
self.company_ELD = self.env.ref("joint_buying_base.company_ELD")
self.company_CHE = self.env.ref("joint_buying_base.company_CHE")
self.company_3PP = self.env.ref("joint_buying_base.company_3PP")

# Test Section
def test_601_double_link_supplier_to_joint_buying_partner(self):
Expand Down
2 changes: 2 additions & 0 deletions joint_buying_product/demo/product_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<field name="company_id" ref="joint_buying_base.company_ELD"/>
<field name="name">Orangette Sachet 200gr</field>
<field name="price">12</field>
<field name="weight">0.210</field>
</record>

<record id="product_ELD_gingembrettes" model="product.product">
Expand All @@ -142,6 +143,7 @@
<field name="company_id" ref="joint_buying_base.company_ELD"/>
<field name="name">Gingembrette Sachet 200gr</field>
<field name="price">10</field>
<field name="weight">0.210</field>
</record>

<function model="product.product" name="create_joint_buying_product">
Expand Down
2 changes: 1 addition & 1 deletion joint_buying_product/models/joint_buying_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def correct_purchase_state(self):
@api.multi
def button_see_request(self):
self.ensure_one()
xml_action = "joint_buying_product.action_joint_buying_transport_request"
xml_action = "joint_buying_base.action_joint_buying_transport_request"
xml_view = "joint_buying_base.view_joint_buying_transport_request_form"
action = self.env.ref(xml_action).read()[0]
action["views"] = [(self.env.ref(xml_view).id, "form")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="model">joint.buying.transport.request</field>
<field name="inherit_id" ref="joint_buying_base.view_joint_buying_transport_request_form"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="order_id"/>
</field>
<xpath expr="//field[@name='manual_start_date']/.." position="before">
<group colspan="4">
<field name="order_id" attrs="{'invisible': [('order_id', '=', False)]}"/>
</group>
</xpath>
</field>
</record>

Expand Down
7 changes: 6 additions & 1 deletion joint_buying_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"license": "AGPL-3",
"depends": [
"sale",
# OCA
"sale_order_weight",
# GRAP
"joint_buying_product",
],
Expand All @@ -21,7 +23,10 @@
"views/view_joint_buying_transport_request.xml",
"views/view_sale_order.xml",
],
"demo": ["demo/sale_order.xml"],
"demo": [
"demo/sale_order.xml",
"demo/joint_buying_transport_request.xml",
],
"installable": True,
"auto_install": True,
}
16 changes: 16 additions & 0 deletions joint_buying_sale/demo/joint_buying_transport_request.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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).
-->
<odoo>

<record id="request_lse_cda_week_0" model="joint.buying.transport.request">
<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>
35 changes: 33 additions & 2 deletions joint_buying_sale/demo/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>

<!-- First Sale Order-->
<record id="sale_order_1" model="sale.order">
<field name="partner_id" ref="base.res_partner_2"/>
<field name="partner_invoice_id" ref="base.res_partner_2"/>
Expand All @@ -17,7 +18,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="date_order" eval="(DateTime.today() - relativedelta(months=1)).strftime('%Y-%m-%d %H:%M')"/>
</record>

<record id="sale_order_line_1" model="sale.order.line">
<record id="sale_order_1_line_1" model="sale.order.line">
<field name="order_id" ref="sale_order_1"/>
<field name="name">[ELD-ORANGETTE] Orangette Sachet 200gr</field>
<field name="product_id" ref="joint_buying_product.product_ELD_orangettes"/>
Expand All @@ -26,7 +27,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="price_unit">15.00</field>
</record>

<record id="sale_order_line_2" model="sale.order.line">
<record id="sale_order_1_line_2" model="sale.order.line">
<field name="order_id" ref="sale_order_1"/>
<field name="name">[ELD-GINGEMBRETTE] Gingembrette Sachet 200gr</field>
<field name="product_id" ref="joint_buying_product.product_ELD_gingembrettes"/>
Expand All @@ -35,4 +36,34 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="price_unit">12.00</field>
</record>

<!-- Second Sale Order-->
<record id="sale_order_2" model="sale.order">
<field name="partner_id" ref="base.res_partner_3"/>
<field name="partner_invoice_id" ref="base.res_partner_3"/>
<field name="partner_shipping_id" ref="base.res_partner_3"/>
<field name="user_id" ref="base.user_admin"/>
<field name="company_id" ref="joint_buying_base.company_ELD"/>
<field name="pricelist_id" ref="product.list0"/>
<field name="team_id" ref="sales_team.team_sales_department"/>
<field name="date_order" eval="(DateTime.today() + relativedelta(days=5)).strftime('%Y-%m-%d %H:%M')"/>
</record>

<record id="sale_order_2_line_1" model="sale.order.line">
<field name="order_id" ref="sale_order_2"/>
<field name="name">[ELD-ORANGETTE] Orangette Sachet 200gr</field>
<field name="product_id" ref="joint_buying_product.product_ELD_orangettes"/>
<field name="product_uom_qty">20</field>
<field name="product_uom" ref="uom.product_uom_unit"/>
<field name="price_unit">15.00</field>
</record>

<record id="sale_order_2_line_2" model="sale.order.line">
<field name="order_id" ref="sale_order_2"/>
<field name="name">[ELD-GINGEMBRETTE] Gingembrette Sachet 200gr</field>
<field name="product_id" ref="joint_buying_product.product_ELD_gingembrettes"/>
<field name="product_uom_qty">30</field>
<field name="product_uom" ref="uom.product_uom_unit"/>
<field name="price_unit">12.00</field>
</record>

</odoo>
46 changes: 46 additions & 0 deletions joint_buying_sale/models/joint_buying_transport_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,50 @@ class JointBuyingTransportRequest(models.Model):
readonly=True,
help="Sale order in the local database of the"
" company that requires transport.",
ondelete="cascade",
)

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

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

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_qty",
"sale_order_id.order_line.product_uom.name",
]
return res

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

for request in self.filtered(lambda x: x.sale_order_id):
request.amount_untaxed = request.sale_order_id.amount_untaxed

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

for request in self.filtered(lambda x: x.sale_order_id):
request.total_weight = request.sale_order_id.total_ordered_weight

Check warning on line 52 in joint_buying_sale/models/joint_buying_transport_request.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_sale/models/joint_buying_transport_request.py#L52

Added line #L52 was not covered by tests

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

for request in self.filtered(lambda x: x.sale_order_id):
request.can_change_date = True
request.can_change_extra_data = False
request.can_change_partners = True

Check warning on line 62 in joint_buying_sale/models/joint_buying_transport_request.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_sale/models/joint_buying_transport_request.py#L60-L62

Added lines #L60 - L62 were not covered by tests
15 changes: 8 additions & 7 deletions joint_buying_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@
class SaleOrder(models.Model):
_inherit = "sale.order"

joint_buying_has_transport_request = fields.Boolean(
compute="_compute_joint_buying_has_transport_request",
store=False,
help="Technical field, used to know if the sale order"
" has a related joint buying transport request created.",
joint_buying_transport_request_id = fields.Many2one(
comodel_name="joint.buying.transport.request",
compute="_compute_joint_buying_transport_request",
)

joint_buying_transport_request_ids = fields.One2many(
string="Joint Buying Transport Requests",
comodel_name="joint.buying.transport.request",
inverse_name="sale_order_id",
help="Technical field, used to know if the sale order"
" has a related joint buying transport request created."
" It can contain only 0 or one transport request.",
)

def _compute_joint_buying_has_transport_request(self):
def _compute_joint_buying_transport_request(self):
for order in self:
order.joint_buying_has_transport_request = len(
order.joint_buying_transport_request_id = (

Check warning on line 27 in joint_buying_sale/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_sale/models/sale_order.py#L27

Added line #L27 was not covered by tests
order.joint_buying_transport_request_ids
and order.joint_buying_transport_request_ids[0]
or False
)
23 changes: 10 additions & 13 deletions joint_buying_sale/views/view_sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<button name="action_unlock" position="after">
<button name="%(joint_buying_sale.action_wizard_create_transport_request)d" string="Generate Transport Request"
type="action" class="btn-primary"
attrs="{'invisible': [
('joint_buying_has_transport_request', '=', True),
]}"

<field name="payment_term_id" position="after">
<field name="joint_buying_transport_request_id"
groups="joint_buying_base.group_joint_buying_user"
attrs="{'invisible': [('joint_buying_transport_request_id', '=', False)]}"
/>
</button>
<field name="payment_term_id" position="after">
<field name="joint_buying_has_transport_request" invisible="1"
groups="joint_buying_base.group_joint_buying_user"/>
<button type="action"
name="%(joint_buying_sale.action_wizard_create_transport_request)d"
string="Generate Transport Request"
groups="joint_buying_base.group_joint_buying_user"
attrs="{'invisible': [('joint_buying_transport_request_id', '!=', False)]}"
icon="fa-cogs" class="oe_inline oe_link"/>

</field>
</field>
</record>


</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ def _default_product_ids(self):
def create_transport_request(self):
self.ensure_one()

Check warning on line 66 in joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py#L66

Added line #L66 was not covered by tests

if self.sale_order_id.joint_buying_has_transport_request:
if self.sale_order_id.joint_buying_transport_request_id:
raise UserError(_("There is already a transport demand for this sale."))

Check warning on line 69 in joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py#L69

Added line #L69 was not covered by tests

if self.product_ids.filtered(lambda x: x.weight == 0):
raise UserError(_("Please set a weight for all products."))

Check warning on line 72 in joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py#L72

Added line #L72 was not covered by tests

self.sale_order_id.recalculate_weight()

Check warning on line 74 in joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py#L74

Added line #L74 was not covered by tests

request_vals = {

Check warning on line 76 in joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py#L76

Added line #L76 was not covered by tests
"manual_origin_partner_id": self.origin_partner_id.id,
"manual_destination_partner_id": self.destination_partner_id.id,
"sale_order_id": self.sale_order_id.id,
"manual_start_date": self.start_date,
"manual_origin_partner_id": self.origin_partner_id.id,
"manual_destination_partner_id": self.destination_partner_id.id,
}

self.env["joint.buying.transport.request"].create(request_vals)

Check warning on line 83 in joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py

View check run for this annotation

Codecov / codecov/patch

joint_buying_sale/wizards/joint_buying_create_transport_request_wizard.py#L83

Added line #L83 was not covered by tests

0 comments on commit 51e38e1

Please sign in to comment.