Skip to content

Commit

Permalink
[MIG] website_sale_stock_provisioning_date: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
arantxa-s73 authored and miguel-S73 committed Oct 25, 2024
1 parent 6cd6062 commit 2a2d36e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
46 changes: 38 additions & 8 deletions website_sale_stock_provisioning_date/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,40 @@ class ProductTemplate(models.Model):
"shows the inventory of the product in the website shop."
)

free_qty = fields.Float(
"Free To Use Quantity ",
compute="_compute_quantities",
search="_search_free_qty",
digits="Product Unit of Measure",
compute_sudo=False,
)

def _search_free_qty(self, operator, value):
domain = [("free_qty", operator, value)]
product_variant_query = self.env["product.product"]._search(domain)
return [("product_variant_ids", "in", product_variant_query)]

def _compute_free_qty_dict(self):
prod_available = {}
variants_available = {
p["id"]: p for p in self.product_variant_ids._origin.read(["free_qty"])
}
for template in self:
free_qty = 0
for p in template.product_variant_ids._origin:
free_qty += variants_available[p.id]["free_qty"]
prod_available.setdefault(
template.id, prod_available.get(template.id, {})
).update({"free_qty": free_qty})
return prod_available

def _compute_quantities(self):
result = super()._compute_quantities()
res = self._compute_free_qty_dict()
for template in self:
template.free_qty = res[template.id]["free_qty"]
return result

def _get_next_provisioning_date(self, company):
return self.product_variant_ids._get_next_provisioning_date(company)

Expand All @@ -22,15 +56,13 @@ def _get_combination_info(
combination=False,
product_id=False,
add_qty=1,
pricelist=False,
parent_combination=False,
only_template=False,
):
combination_info = super()._get_combination_info(
combination=combination,
product_id=product_id,
add_qty=add_qty,
pricelist=pricelist,
parent_combination=parent_combination,
only_template=only_template,
)
Expand All @@ -42,13 +74,11 @@ def _get_combination_info(
)
else:
product = self.sudo()
website = self.env["website"].get_current_website()
provisioning_date = False
if (
product.show_next_provisioning_date
and product.qty_available - product.outgoing_qty <= 0
):
website_id = self.env.context.get("website_id")
company = self.env["website"].browse(website_id).company_id
free_qty = website._get_product_available_qty(product)
if product.show_next_provisioning_date and free_qty <= 0:
company = website.company_id
provisioning_date = product._get_next_provisioning_date(company)
provisioning_date = format_date(self.env, provisioning_date)
combination_info.update(provisioning_date=provisioning_date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
<!-- Copyright 2020 Tecnativa - Ernesto Tejeda
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<templates>
<t t-extend="website_sale_stock.product_availability">
<t
t-jquery="div[t-if='!allow_out_of_stock_order and show_availability and cart_qty']"
t-operation="after"
>
<!-- If qty_available - outgoing_qty > 0 or show_next_provisioning_date
is not checked, then provisioning_date is False -->
<t t-inherit="website_sale_stock.product_availability" t-inherit-mode="extension">
<xpath expr="//div[@id='already_in_cart_message']" position="after">
<div
t-if="provisioning_date"
t-attf-class="availability_message_#{product_template} text-success mt16"
Expand All @@ -17,6 +12,6 @@
Next provisioning date: <t t-esc="provisioning_date" />
</span>
</div>
</t>
</xpath>
</t>
</templates>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUpClass(cls):
limit=1,
)
picking_form = Form(
recordp=cls.env["stock.picking"].with_context(
cls.env["stock.picking"].with_context(
default_picking_type_id=incoming_picking_type.id
),
view="stock.view_picking_form",
Expand Down

0 comments on commit 2a2d36e

Please sign in to comment.