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 28, 2024
1 parent 6cd6062 commit 0be5ece
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 57 deletions.
2 changes: 1 addition & 1 deletion website_sale_stock_provisioning_date/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"web.assets_tests": [
"/website_sale_stock_provisioning_date/static/src/js/"
"website_sale_stock_provisioning_date_tour.js",
"website_sale_stock_provisioning_date_tour.esm.js",
],
},
}
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
@@ -0,0 +1,24 @@
/** @odoo-module **/
/* Copyright 2020 Tecnativa - Ernesto Tejeda
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */

import {registry} from "@web/core/registry";
import tourUtils from "@website_sale/js/tours/tour_utils";
import wTourUtils from "@website/js/tours/tour_utils";

registry.category("web_tour.tours").add("website_sale_stock_provisioning_date", {
test: true,
url: "/shop",
steps: () => [
...tourUtils.searchProduct("provisioning date"),
wTourUtils.clickOnElement(
"click on product test",
'.oe_product_cart a:contains("provisioning date")'
),
{
trigger: "a#add_to_cart",
extra_trigger:
".availability_messages:has(span:contains('Next provisioning date:'))",
},
],
});

This file was deleted.

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 All @@ -42,10 +42,61 @@ def setUpClass(cls):
picking = picking_form.save()
picking.action_confirm()

cls.warehouse_1 = cls.env["stock.warehouse"].search(
[("company_id", "=", cls.env.company.id)]
)
# Create two stockable products
cls.product_A = cls.env["product.product"].create(
{
"name": "Product A",
"allow_out_of_stock_order": False,
"type": "product",
"default_code": "E-COM1",
}
)
cls.partner = cls.env["res.partner"].create(
{"name": "Test Partner", "email": "[email protected]"}
)
# Add 10 Product A in WH1 and 15 Product 1 in WH2
quants = (
cls.env["stock.quant"]
.with_context(inventory_mode=True)
.create(
[
{
"product_id": cls.product_A.id,
"inventory_quantity": 10.0,
"location_id": cls.warehouse_1.lot_stock_id.id,
}
]
)
)
quants.action_apply_inventory()
sale = cls.env["sale.order"].create(
{
"partner_id": cls.partner.id,
"order_line": [
(
0,
0,
{
"product_id": cls.product_A.id,
"product_uom_qty": 3,
},
)
],
}
)
sale.action_confirm()

def test_ui_website(self):
"""Test frontend tour."""
self.start_tour(
"/shop",
"website_sale_stock_provisioning_date",
login="admin",
)

def test_search_qty_free(self):
templates = self.env["product.template"].search([("free_qty", ">", 0)])
self.assertEqual(templates.free_qty, 7)

0 comments on commit 0be5ece

Please sign in to comment.