Skip to content

Commit

Permalink
[MIG] rental_base : Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adasatorres committed Sep 16, 2024
1 parent d880da6 commit 272657c
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 136 deletions.
1 change: 0 additions & 1 deletion rental_base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Part of rental-vertical See LICENSE file for full copyright and licensing details.
from . import models
from . import tests
from . import wizard
2 changes: 1 addition & 1 deletion rental_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{
"name": "Rental Base",
"version": "14.0.1.0.1",
"version": "16.0.1.0.0",
"category": "Rental",
"summary": "Manage Rental of Products",
"author": "elego Software Solutions GmbH, Odoo Community Association (OCA)",
Expand Down
72 changes: 39 additions & 33 deletions rental_base/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ class SaleOrder(models.Model):
_inherit = "sale.order"

default_start_date = fields.Date(
string="Default Start Date",
compute="_compute_default_start_date",
readonly=False,
store=True,
)

default_end_date = fields.Date(
string="Default End Date",
compute="_compute_default_end_date",
readonly=False,
store=True,
Expand Down Expand Up @@ -106,49 +104,54 @@ def _check_sale_line_rental(self):
if not line.extension_rental_id:
raise ValidationError(
_(
'Missing "Rental to Extend" on the sale order line '
"with rental service %s."
'Missing "Rental to Extend" on the sale order line'
" with rental service %(name)s."
)
% line.product_id.name
% {"name": line.product_id.name}
)

if line.rental_qty != line.extension_rental_id.rental_qty:
raise ValidationError(
_(
"On the sale order line with rental service %s, "
"you are trying to extend a rental with a rental "
"quantity (%s) that is different from the quantity "
"of the original rental (%s). This is not supported."
)
% (
line.product_id.name,
line.rental_qty,
line.extension_rental_id.rental_qty,
"On the sale order line with"
" rental service %(name)s"
" ,you are trying to extend a "
"rental with a rental "
"quantity (%(rental_qty)s) "
"that is different from the quantity "
"of the original rental "
"(%(ext_rental_qty)s). "
"This is not supported."
)
% {
"name": line.product_id.name,
"rental_qty": line.rental_qty,
"ext_rental_qty": line.extension_rental_id.rental_qty,
}
)
if line.rental_type in ("new_rental", "rental_extension"):
if not line.product_id.rented_product_id:
raise ValidationError(
_(
'On the "new rental" sale order line with product '
'"%s", we should have a rental service product!'
'"%(name)s", we should have a rental service product!'
)
% (line.product_id.name)
% {"name": line.product_id.name}
)
elif line.sell_rental_id:
if line.product_uom_qty != line.sell_rental_id.rental_qty:
raise ValidationError(
_(
"On the sale order line with product %s "
"On the sale order line with product %(name)s "
"you are trying to sell a rented product with a "
"quantity (%s) that is different from the rented "
"quantity (%s). This is not supported."
)
% (
line.product_id.name,
line.product_uom_qty,
line.sell_rental_id.rental_qty,
"quantity (%(qty)s) that is different from the rented "
"quantity (%(sell_rental_qty)s). This is not supported."
)
% {
"name": line.product_id.name,
"qty": line.product_uom_qty,
"sell_rental_qty": line.sell_rental_id.rental_qty,
}
)

def _prepare_invoice_line(self, **optional_values):
Expand Down Expand Up @@ -218,10 +221,10 @@ def update_start_end_date(self, date_start, date_end):
]:
raise exceptions.UserError(
_(
"Outgoing shipment is in state %s. You cannot change \
the start date anymore."
"Outgoing shipment is in state %(state)s."
" You cannot change the start date anymore."
)
% rental.out_move_id.state
% {"state": rental.out_move_id.state}
)
rental.out_move_id.date = datetime_start
if rentals and date_end:
Expand All @@ -235,10 +238,10 @@ def update_start_end_date(self, date_start, date_end):
]:
raise exceptions.UserError(
_(
"Incoming shipment is in state %s. You cannot change \
the end date anymore."
"Incoming shipment is in state %s."
" You cannot change the end date anymore."
)
% rental.in_move_id.state
% {"state": rental.in_move_id.state}
)
rental.in_move_id.date = datetime_end

Expand Down Expand Up @@ -293,14 +296,17 @@ def write(self, values):
if messages:
messages.append(
_(
"\nOrder: %s\n"
"Line with product: '%s'\n\n"
"\nOrder: %(order)s\n"
"Line with product: '%(product)s'\n\n"
"Please use instead the button 'Update Times' "
"in the order to correctly update the order "
"line's times, its timeline entry, contract and "
"its stock moves and pickings as required."
)
% (sol.order_id.name, sol.product_id.display_name)
% {
"order": sol.order_id.name,
"product": sol.product_id.display_name,
}
)
raise exceptions.UserError("\n".join(messages))
return super(SaleOrderLine, self).write(values)
4 changes: 2 additions & 2 deletions rental_base/tests/test_update_time_rental_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_00_update_time_rental_order(self):
wizard_1 = (
self.env["update.sale.line.date"]
.with_context(
{
**{
"active_model": "sale.order",
"active_ids": rental_order_1.ids,
}
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_00_update_time_rental_order(self):
wizard_2 = (
self.env["update.sale.line.date"]
.with_context(
{
**{
"active_model": "sale.order",
"active_ids": rental_order_1.ids,
}
Expand Down
76 changes: 25 additions & 51 deletions rental_base/views/sale_view.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<!-- Hide fields inserted by sale_rental module to move them to new location -->
<record id="sale_rental" model="ir.ui.view">
<field name="name">rental_base.sale_rental</field>
Expand All @@ -24,12 +23,12 @@
</xpath>
</field>
</record>

<!-- Hide fields inserted by sale_start_end_dates module to move them to new location -->
<record id="sale_start_end_dates" model="ir.ui.view">
<field name="name">rental_base.sale_start_end_dates</field>
<field name="model">sale.order</field>
<field name="priority">110</field> <!--Priority greater than 100-->
<field name="priority">110</field>
<!--Priority greater than 100-->
<field name="inherit_id" ref="sale_start_end_dates.view_order_form" />
<field name="arch" type="xml">
<!-- Use of position=replace: It is necessary to adjust view design -->
Expand All @@ -47,22 +46,17 @@
</field>
</field>
</record>

<!-- Hide fields inserted by sale_stock module to move them to new location -->
<record id="sale_stock" model="ir.ui.view">
<field name="name">rental_base.sale_stock</field>
<field name="model">sale.order</field>
<field
name="inherit_id"
ref="sale_stock.view_order_form_inherit_sale_stock"
/>
<field name="arch" type="xml">
<xpath expr="//field[@name='product_packaging']" position="attributes">
<attribute name="attrs">{'invisible': 1}</attribute>
</xpath>
</field>
<field name="name">rental_base.sale_stock</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale_stock.view_order_form_inherit_sale_stock" />
<field name="arch" type="xml">
<xpath expr="//field[@name='product_packaging_id']" position="attributes">
<attribute name="attrs">{'invisible': 1}</attribute>
</xpath>
</field>
</record>

<!-- Hide fields inserted by sale_order_type module to move them to new location -->
<record id="sale_order_type" model="ir.ui.view">
<field name="name">rental_base.sale_order_type</field>
Expand All @@ -76,7 +70,6 @@
</xpath>
</field>
</record>

<record id="view_order_form" model="ir.ui.view">
<field name="name">rental_base.view_order_form</field>
<field name="model">sale.order</field>
Expand Down Expand Up @@ -105,7 +98,6 @@
>
<attribute name="attrs">{'invisible': 1}</attribute>
</xpath>

<!-- Sheet -->
<xpath expr="//field[@name='partner_id']" position="before">
<field
Expand All @@ -130,15 +122,8 @@
force_save="1"
/>
</xpath>

<!-- Sale Order Lines -->
<!-- Hide fields inserted by sale module to move them to new location -->
<xpath
expr="//group[field[@name='analytic_tag_ids']]"
position="attributes"
>
<attribute name="id">further_rental_info</attribute>
</xpath>
<xpath expr="//field[@name='tax_id']" position="attributes">
<attribute name="attrs">{'invisible': 1}</attribute>
</xpath>
Expand All @@ -148,10 +133,7 @@
<xpath expr="//div[field[@name='customer_lead']]" position="attributes">
<attribute name="attrs">{'invisible': 1}</attribute>
</xpath>
<!-- <xpath expr="//label[@for='analytic_tag_ids']" position="attributes">
<attribute name="attrs">{'invisible': 1}</attribute>
</xpath> -->
<xpath expr="//field[@name='analytic_tag_ids']" position="attributes">
<xpath expr="//field[@name='analytic_distribution']" position="attributes">
<attribute name="attrs">{'invisible': 1}</attribute>
</xpath>
<xpath expr="//label[@for='qty_delivered']" position="attributes">
Expand Down Expand Up @@ -185,7 +167,6 @@
name="attrs"
>{'invisible': [('display_type', '=', False)]}</attribute>
</xpath>

<!-- Group: Order Information -->
<xpath expr="//group[field[@name='product_id']]" position="attributes">
<attribute name="id">order_info</attribute>
Expand Down Expand Up @@ -245,8 +226,10 @@
/>
<field name="name" nolabel="1" colspan="2" />
</xpath>

<xpath expr="//group[@id='further_rental_info']" position="inside">
<xpath
expr="//group//field[@name='analytic_distribution']"
position="inside"
>
<!-- Group: Rental Settings -->
<group id="rental_settings" string="Rental Settings" colspan="4">
<field name="rental" />
Expand All @@ -270,7 +253,6 @@
domain="[('rented_product_id', '=', product_id), ('state', '=', 'out')]"
/>
</group>

<!-- Group: Rental Times -->
<group
id="rental_times"
Expand Down Expand Up @@ -343,12 +325,11 @@
attrs="{'readonly': 1}"
/>
</div>
</group>

</group>
<!-- Group: Transport -->
<group id="rental_transport" string="Transport" colspan="4">
<field
name="product_packaging"
name="product_packaging_id"
attrs="{'invisible': [('product_id', '=', False)]}"
context="{'default_product_id': product_id,
'tree_view_ref':'product.product_packaging_tree_view',
Expand All @@ -362,7 +343,6 @@
<field name="customer_lead" class="oe_inline" /> Day(s)
</div>
</group>

<!-- Group: Invoicing -->
<group id="rental_invoicing" string="Invoicing" colspan="4">
<field
Expand All @@ -374,23 +354,17 @@
attrs="{'readonly': [('qty_invoiced', '&gt;', 0)]}"
/>
<label
for="analytic_tag_ids"
groups="analytic.group_analytic_tags"
for="analytic_distribution"
groups="analytic.group_analytic_accounting"
/>
<field
name="analytic_distribution"
widget="analytic_distribution"
groups="analytic.group_analytic_accounting"
options="{'product_field': 'product_id', 'business_domain': 'sale_order'}"
/>
<div>
<field
name="analytic_tag_ids"
widget="many2many_tags"
groups="analytic.group_analytic_tags"
options="{'color_field': 'color'}"
/>
</div>
</group>

</xpath>

</field>
</record>


</odoo>
Loading

0 comments on commit 272657c

Please sign in to comment.