Skip to content

Commit

Permalink
[+] transport request demo data
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Oct 18, 2023
1 parent 6f124c4 commit eb3db66
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions joint_buying_product/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"demo/product_product.xml",
"demo/res_partner.xml",
"demo/joint_buying_frequency.xml",
"demo/joint_buying_transport_request.xml",
"demo/ir_cron.xml",
],
"installable": True,
Expand Down
13 changes: 13 additions & 0 deletions joint_buying_product/demo/joint_buying_transport_request.xml
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>
49 changes: 49 additions & 0 deletions joint_buying_product/models/joint_buying_transport_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,33 @@ class JointBuyingTransportRequest(models.Model):
_name = "joint.buying.transport.request"
_description = "Joint Buying Transport Request"

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)",
Expand All @@ -36,6 +56,21 @@ class JointBuyingTransportRequest(models.Model):
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"),
Expand All @@ -61,13 +96,27 @@ class JointBuyingTransportRequest(models.Model):
)

# Compute Section
@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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<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-info="amount_untaxed == 0 and total_weight == 0">
<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>
Expand All @@ -43,8 +48,12 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<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"/>
Expand Down

0 comments on commit eb3db66

Please sign in to comment.