-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] joint_buying_product : new transport.request model
- add hook on (grouped).orders to create / unlink related transport requests at the good moment - add transport request demo data [REF] joint_buying_base: Simplification, adding joint_buying_code on res.partner model
- Loading branch information
1 parent
ad47ce0
commit aff9e34
Showing
11 changed files
with
302 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
joint_buying_product/demo/joint_buying_transport_request.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<odoo> | ||
|
||
<record id="request_vev_cda" model="joint.buying.transport.request"> | ||
<field name="manual_origin_partner_id" model="res.partner" eval="obj().env.ref('joint_buying_base.company_VEV').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() + relativedelta(day=8)).strftime('%Y-%m-%d 07:00')"/> | ||
<field name="manual_amount_untaxed">200</field> | ||
<field name="manual_total_weight">50</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
joint_buying_product/models/joint_buying_transport_request.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# 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 odoo import api, fields, models | ||
|
||
from odoo.addons import decimal_precision as dp | ||
from odoo.addons.joint_buying_base.models.res_partner import ( | ||
_JOINT_BUYING_PARTNER_CONTEXT, | ||
) | ||
|
||
|
||
class JointBuyingTransportRequest(models.Model): | ||
_name = "joint.buying.transport.request" | ||
_description = "Joint Buying Transport Request" | ||
|
||
name = fields.Char(readonly=True, compute="_compute_name", store=True) | ||
|
||
state = fields.Selection( | ||
selection=[ | ||
("to_compute", "To Compute"), | ||
("computed", "Computed"), | ||
], | ||
required=True, | ||
readonly=True, | ||
default="to_compute", | ||
) | ||
|
||
order_id = fields.Many2one( | ||
comodel_name="joint.buying.purchase.order", | ||
string="Order", | ||
readonly=True, | ||
ondelete="cascade", | ||
) | ||
|
||
manual_start_date = fields.Datetime( | ||
string="Start Date (Manual)", | ||
) | ||
|
||
start_date = fields.Datetime( | ||
string="Start Date", | ||
compute="_compute_start_date", | ||
store=True, | ||
) | ||
|
||
manual_origin_partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
string="Origin (Manual)", | ||
context=_JOINT_BUYING_PARTNER_CONTEXT, | ||
domain="[('is_joint_buying_stage', '=', True)]", | ||
) | ||
|
||
origin_partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
compute="_compute_origin_partner_id", | ||
string="Origin", | ||
store=True, | ||
context=_JOINT_BUYING_PARTNER_CONTEXT, | ||
) | ||
|
||
manual_destination_partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
string="Destination (Manual)", | ||
context=_JOINT_BUYING_PARTNER_CONTEXT, | ||
domain="[('is_joint_buying_stage', '=', True)]", | ||
) | ||
|
||
destination_partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
compute="_compute_destination_partner_id", | ||
string="Destination", | ||
store=True, | ||
context=_JOINT_BUYING_PARTNER_CONTEXT, | ||
) | ||
|
||
manual_amount_untaxed = fields.Float( | ||
string="Untaxed Amount (Manual)", | ||
digits=dp.get_precision("Product Price"), | ||
) | ||
|
||
amount_untaxed = fields.Float( | ||
string="Untaxed Amount", | ||
compute="_compute_amount_untaxed", | ||
store=True, | ||
digits=dp.get_precision("Product Price"), | ||
) | ||
|
||
manual_total_weight = fields.Float( | ||
string="Weight (Manual)", | ||
digits=dp.get_precision("Stock Weight"), | ||
) | ||
|
||
total_weight = fields.Float( | ||
string="Weight", | ||
compute="_compute_weight", | ||
store=True, | ||
digits=dp.get_precision("Stock Weight"), | ||
) | ||
|
||
tour_line_ids = fields.Many2many( | ||
comodel_name="joint.buying.tour.line", | ||
string="Route Lines", | ||
) | ||
|
||
# Compute Section | ||
@api.depends("origin_partner_id", "destination_partner_id", "start_date") | ||
def _compute_name(self): | ||
for request in self: | ||
request.name = ( | ||
f"{request.origin_partner_id.joint_buying_code}" | ||
f" -> {request.destination_partner_id.joint_buying_code}" | ||
f" ({request.start_date})" | ||
) | ||
|
||
@api.depends("manual_start_date", "order_id.deposit_date") | ||
def _compute_start_date(self): | ||
for request in self.filtered(lambda x: x.manual_start_date): | ||
request.start_date = request.manual_start_date | ||
for request in self.filtered(lambda x: not x.manual_start_date): | ||
request.start_date = request.order_id.deposit_date | ||
|
||
@api.depends("manual_origin_partner_id", "order_id.deposit_partner_id") | ||
def _compute_origin_partner_id(self): | ||
for request in self.filtered(lambda x: x.manual_origin_partner_id): | ||
request.origin_partner_id = request.manual_origin_partner_id | ||
for request in self.filtered(lambda x: not x.manual_origin_partner_id): | ||
request.origin_partner_id = request.order_id.deposit_partner_id | ||
|
||
@api.depends("manual_destination_partner_id", "order_id.deposit_partner_id") | ||
def _compute_destination_partner_id(self): | ||
for request in self.filtered(lambda x: x.manual_destination_partner_id): | ||
request.destination_partner_id = request.manual_destination_partner_id | ||
for request in self.filtered(lambda x: not x.manual_destination_partner_id): | ||
request.destination_partner_id = request.order_id.customer_id | ||
|
||
@api.depends("manual_amount_untaxed", "order_id.amount_untaxed") | ||
def _compute_amount_untaxed(self): | ||
for request in self.filtered(lambda x: x.manual_amount_untaxed): | ||
request.amount_untaxed = request.manual_amount_untaxed | ||
for request in self.filtered(lambda x: not x.manual_amount_untaxed): | ||
request.amount_untaxed = request.order_id.amount_untaxed | ||
|
||
@api.depends("manual_total_weight", "order_id.total_weight") | ||
def _compute_weight(self): | ||
for request in self.filtered(lambda x: x.manual_total_weight): | ||
request.total_weight = request.manual_total_weight | ||
for request in self.filtered(lambda x: not x.manual_total_weight): | ||
request.total_weight = request.order_id.total_weight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
joint_buying_product/views/view_joint_buying_transport_request.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?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_joint_buying_transport_request_search" model="ir.ui.view"> | ||
<field name="model">joint.buying.transport.request</field> | ||
<field name="arch" type="xml"> | ||
<search> | ||
<field name="origin_partner_id"/> | ||
<field name="destination_partner_id"/> | ||
<field name="order_id"/> | ||
<field name="state"/> | ||
</search> | ||
</field> | ||
</record> | ||
|
||
<record id="view_joint_buying_transport_request_tree" model="ir.ui.view"> | ||
<field name="model">joint.buying.transport.request</field> | ||
<field name="arch" type="xml"> | ||
<tree decoration-muted="amount_untaxed == 0 and total_weight == 0" decoration-info="state == 'to_compute'"> | ||
<field name="start_date"/> | ||
<field name="origin_partner_id"/> | ||
<field name="destination_partner_id"/> | ||
<field name="amount_untaxed"/> | ||
<field name="total_weight"/> | ||
<field name="order_id"/> | ||
<field name="state"/> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record id="view_joint_buying_transport_request_form" model="ir.ui.view"> | ||
<field name="model">joint.buying.transport.request</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<header /> | ||
<sheet> | ||
<div class="oe_button_box" name="button_box"> | ||
</div> | ||
<div class="oe_title"> | ||
<h1> | ||
<field name="name"/> | ||
</h1> | ||
</div> | ||
<group col="4"> | ||
<field name="order_id"/> | ||
<newline/> | ||
<field name="start_date"/> | ||
<field name="manual_start_date"/> | ||
<field name="origin_partner_id"/> | ||
<field name="manual_origin_partner_id"/> | ||
<field name="destination_partner_id"/> | ||
<field name="manual_destination_partner_id"/> | ||
<field name="total_weight"/> | ||
<field name="manual_total_weight"/> | ||
<field name="amount_untaxed"/> | ||
<field name="manual_amount_untaxed"/> | ||
</group> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="action_joint_buying_transport_request" model="ir.actions.act_window"> | ||
<field name="name">Transport Requests</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">joint.buying.transport.request</field> | ||
<field name="view_type">form</field> | ||
<field name="view_mode">tree,form</field> | ||
</record> | ||
|
||
<menuitem id="menu_joint_buying_transport_request" | ||
name="Transport Requests" | ||
parent="joint_buying_product.menu_transport" | ||
action="action_joint_buying_transport_request" | ||
sequence="1" | ||
groups="joint_buying_base.group_joint_buying_user" | ||
/> | ||
|
||
</odoo> |