Skip to content

Commit

Permalink
[MIG] sale_recovery_moment: Migration to 16.0 (from 12.0)
Browse files Browse the repository at this point in the history
- Simplify sales date. Now only one field, computed readonly = False
- Classic V16 adaptation
  • Loading branch information
legalsylvain committed Feb 17, 2025
1 parent bf49028 commit e515619
Show file tree
Hide file tree
Showing 26 changed files with 128 additions and 249 deletions.
1 change: 0 additions & 1 deletion sale_recovery_moment/ROADMAP.rst

This file was deleted.

7 changes: 4 additions & 3 deletions sale_recovery_moment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

{
"name": "Sale - Recovery Moments",
"version": "12.0.1.2.2",
"version": "16.0.1.0.0",
"summary": "Manage Recovery Moments and Places for Sale Order",
"category": "Sale",
"author": "GRAP",
"website": "https://github.com/grap/grap-odoo-business",
"license": "AGPL-3",
"depends": [
# Odoo
"sale_stock",
"stock_picking_report_summary",
# OCA
# "stock_picking_report_summary",
],
"data": [
"security/ir_rule.xml",
Expand All @@ -34,7 +36,6 @@
"demo/sale_recovery_moment_group.xml",
"demo/sale_recovery_moment.xml",
"demo/sale_order.xml",
"demo/res_groups.xml",
],
"images": [
"static/description/sale_recovery_place_tree.png",
Expand Down
17 changes: 0 additions & 17 deletions sale_recovery_moment/demo/res_groups.xml

This file was deleted.

4 changes: 2 additions & 2 deletions sale_recovery_moment/demo/sale_recovery_moment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

<record id="recovery_moment_without_group" model="sale.recovery.moment">
<field name="place_id" ref="recovery_place_white_house"/>
<field name="specific_min_sale_date" eval="(DateTime.today() + relativedelta(days=-50) + relativedelta(hours=20)).strftime('%Y-%m-%d %H:%M')"/>
<field name="specific_max_sale_date" eval="(DateTime.today() + relativedelta(days=-48) + relativedelta(hours=23)).strftime('%Y-%m-%d %H:%M')"/>
<field name="min_sale_date" eval="(DateTime.today() + relativedelta(days=-50) + relativedelta(hours=20)).strftime('%Y-%m-%d %H:%M')"/>
<field name="max_sale_date" eval="(DateTime.today() + relativedelta(days=-48) + relativedelta(hours=23)).strftime('%Y-%m-%d %H:%M')"/>
<field name="min_recovery_date" eval="(DateTime.today() + relativedelta(days=-46) + relativedelta(hours=10)).strftime('%Y-%m-%d %H:%M')"/>
<field name="max_recovery_date" eval="(DateTime.today() + relativedelta(days=-46) + relativedelta(hours=12)).strftime('%Y-%m-%d %H:%M')"/>
</record>
Expand Down
10 changes: 0 additions & 10 deletions sale_recovery_moment/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,6 @@ msgstr "Article pour les frais de livraison"
msgid "Short Name"
msgstr "Nom court"

#. module: sale_recovery_moment
#: model:ir.model.fields,field_description:sale_recovery_moment.field_sale_recovery_moment__specific_max_sale_date
msgid "Specific Maximum date for the Sale"
msgstr "Date maximum spécifique pour la vente"

#. module: sale_recovery_moment
#: model:ir.model.fields,field_description:sale_recovery_moment.field_sale_recovery_moment__specific_min_sale_date
msgid "Specific Minimum date for the Sale"
msgstr "Date minimum spécifique pour la vente"

#. module: sale_recovery_moment
#: model:ir.model.fields,field_description:sale_recovery_moment.field_sale_recovery_moment__state
#: model:ir.model.fields,field_description:sale_recovery_moment.field_sale_recovery_moment_group__state
Expand Down
2 changes: 0 additions & 2 deletions sale_recovery_moment/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ def create(self, vals_list):
self._set_commitment_date_from_moment_id(vals)
return super().create(vals_list)

@api.multi
def write(self, vals):
self._set_commitment_date_from_moment_id(vals)
return super().write(vals)

@api.multi
def action_confirm(self):
SaleOrderLine = self.env["sale.order.line"]
for order in self.filtered(lambda x: x.recovery_moment_id.place_id):
Expand Down
113 changes: 35 additions & 78 deletions sale_recovery_moment/models/sale_recovery_moment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ class SaleRecoveryMoment(models.Model):
("finished_recovery", "Finished Recovery"),
]

# Columns Section
code = fields.Char(
string="Code",
readonly=True,
required=True,
default="/",
)
code = fields.Char(readonly=True, required=True, default="/")

name = fields.Char(string="Name", compute="_compute_name", store=True)
name = fields.Char(compute="_compute_name", store=True)

place_id = fields.Many2one(
comodel_name="sale.recovery.place", string="Place", required=True
Expand All @@ -41,6 +35,7 @@ class SaleRecoveryMoment(models.Model):
string="Recovery Group",
comodel_name="sale.recovery.moment.group",
ondelete="cascade",
readonly=True,
)

company_id = fields.Many2one(
Expand All @@ -50,24 +45,22 @@ class SaleRecoveryMoment(models.Model):
default=lambda x: x._default_company_id(),
)

specific_min_sale_date = fields.Datetime(
string="Specific Minimum date for the Sale"
)

specific_max_sale_date = fields.Datetime(
string="Specific Maximum date for the Sale"
)

min_sale_date = fields.Datetime(
string="Minimum date for the Sale",
compute="_compute_sale_date",
store=True,
readonly=False,
required=True,
precompute=True,
)

max_sale_date = fields.Datetime(
string="Maximum date for the Sale",
compute="_compute_sale_date",
store=True,
readonly=False,
required=True,
precompute=True,
)

min_recovery_date = fields.Datetime(
Expand All @@ -78,77 +71,54 @@ class SaleRecoveryMoment(models.Model):
string="Maximum date for the Recovery", required=True
)

description = fields.Text(string="Description")
description = fields.Text()

max_order_qty = fields.Integer("Max Order Quantity")
max_order_qty = fields.Integer(string="Max Order Quantity")

order_ids = fields.One2many(
string="Sale Orders",
comodel_name="sale.order",
inverse_name="recovery_moment_id",
string="Sale Orders",
readonly=True,
)

order_qty = fields.Integer(
compute="_compute_order_multi",
multi="order",
store=True,
string="Sale Orders Quantity",
string="Sale Orders Quantity", compute="_compute_order_multi", store=True
)

valid_order_qty = fields.Integer(
compute="_compute_order_multi",
multi="order",
store=True,
string="Valid Sale Orders Quantity",
string="Valid Sale Orders Quantity", compute="_compute_order_multi", store=True
)

is_complete = fields.Boolean(
compute="_compute_order_multi",
multi="order",
store=True,
string="Is Complete",
)
is_complete = fields.Boolean(compute="_compute_order_multi", store=True)

quota_description = fields.Char(
compute="_compute_order_multi",
multi="order",
store=True,
string="Quota Description",
)
quota_description = fields.Char(compute="_compute_order_multi", store=True)

picking_ids = fields.One2many(
string="Delivery Orders",
comodel_name="stock.picking",
inverse_name="recovery_moment_id",
string="Delivery Orders",
readonly=True,
)

picking_qty = fields.Integer(
compute="_compute_picking_multi",
multi="picking",
store=True,
string="Delivery Orders Quantity",
string="Delivery Orders Quantity", compute="_compute_picking_multi", store=True
)

valid_picking_qty = fields.Integer(
string="Valid Delivery Orders Quantity",
compute="_compute_picking_multi",
multi="picking",
store=True,
string="Valid Delivery Orders Quantity",
)

state = fields.Selection(
compute="_compute_state",
string="State",
search="_search_state",
selection=_STATE_SELECTION,
compute="_compute_state", search="_search_state", selection=_STATE_SELECTION
)

# Defaults Section
@api.model
def _default_company_id(self):
return self.env.user.company_id
return self.env.company

# Overload Section
@api.model_create_multi
Expand All @@ -157,7 +127,6 @@ def create(self, vals_list):
vals["code"] = self.env["ir.sequence"].next_by_code("sale.recovery.moment")
return super().create(vals_list)

@api.multi
def unlink(self):
if self.filtered(lambda x: x.valid_order_qty):
raise UserError(
Expand All @@ -171,7 +140,6 @@ def unlink(self):
return super().unlink()

# Compute Section
@api.multi
def _compute_state(self):
now = datetime.now()
for moment in self:
Expand All @@ -186,29 +154,19 @@ def _compute_state(self):
else:
moment.state = "finished_recovery"

@api.multi
@api.depends(
"group_id",
"group_id.min_sale_date",
"group_id.max_sale_date",
"specific_min_sale_date",
"specific_max_sale_date",
)
def _compute_sale_date(self):
for moment in self:
if moment.specific_min_sale_date:
moment.min_sale_date = moment.specific_min_sale_date
elif moment.group_id:
moment.min_sale_date = moment.group_id.min_sale_date
else:
moment.max_sale_date = False
if moment.specific_max_sale_date:
moment.max_sale_date = moment.specific_max_sale_date
elif moment.group_id:
moment.max_sale_date = moment.group_id.max_sale_date
else:
moment.min_sale_date = False
for moment in self.filtered(lambda x: x.group_id):
moment.min_sale_date = moment.group_id.min_sale_date
moment.max_sale_date = moment.group_id.max_sale_date
for moment in self.filtered(lambda x: not x.group_id):
moment.max_sale_date = False
moment.min_sale_date = False

@api.multi
@api.depends(
"order_ids",
"order_ids.recovery_moment_id",
Expand All @@ -232,18 +190,19 @@ def _compute_order_multi(self):

# Update Quota Description Field
if recovery_moment.max_order_qty:
recovery_moment.quota_description = _("%d / %d Orders") % (
recovery_moment.valid_order_qty,
recovery_moment.max_order_qty,
recovery_moment.quota_description = _(
"%(valid_order_qty)d / %(max_order_qty)d Orders",
valid_order_qty=recovery_moment.valid_order_qty,
max_order_qty=recovery_moment.max_order_qty,
)
elif recovery_moment.valid_order_qty:
recovery_moment.quota_description = _("%d Order(s)") % (
recovery_moment.valid_order_qty
recovery_moment.quota_description = _(
"%(valid_order_qty)d Order(s)",
valid_order_qty=recovery_moment.valid_order_qty,
)
else:
recovery_moment.quota_description = _("No Orders")

@api.multi
@api.depends("picking_ids", "picking_ids.recovery_moment_id", "picking_ids.state")
def _compute_picking_multi(self):
# We use sudo for the following case:
Expand All @@ -263,7 +222,6 @@ def _compute_picking_multi(self):
)
)

@api.multi
@api.depends("code", "min_recovery_date", "place_id", "group_id.short_name")
def _compute_name(self):
for moment in self.filtered(lambda x: x.group_id):
Expand Down Expand Up @@ -319,7 +277,6 @@ def _search_state(self, operator, operand):
return [("id", "in", [x[0] for x in res])]

# Constraint Section
@api.multi
@api.constrains("min_recovery_date", "max_recovery_date")
def _check_recovery_dates(self):
for moment in self:
Expand Down
Loading

0 comments on commit e515619

Please sign in to comment.