Skip to content

Commit

Permalink
[IMP] product_template_year_consumption: Add two new fields sales_cou…
Browse files Browse the repository at this point in the history
…nt and months_with_stock_sales_count
  • Loading branch information
unaiberis committed Oct 10, 2024
1 parent 3fc65e3 commit 3581d83
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions product_template_year_consumption/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"category": "Stock",
"depends": [
"stock",
"sale",
],
"data": [
"views/product_product_views.xml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,24 @@ class StockWarehouseOrderpoint(models.Model):
months_with_stock = fields.Integer(
string="Months with stock", related="product_id.months_with_stock"
)
sales_count = fields.Float(
string="Sales Count", related="product_id.sales_count", store=True
)
months_with_stock_sales_count = fields.Float(
string="Months with Stock (Sales Count)",
compute="_compute_months_with_stock_sales_count",
)

def _compute_months_with_stock_sales_count(self):
for orderpoint in self:
months_with_stock = 0
consumed_last_twelve_months = orderpoint.consumed_last_twelve_months

if consumed_last_twelve_months:
if orderpoint.sales_count:
months_with_stock = (
orderpoint.virtual_available
/ (consumed_last_twelve_months / 12)
* (orderpoint.sales_count / 12)
)
orderpoint.months_with_stock_sales_count = months_with_stock
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
<field name="route_id" position="before">
<field name="consumed_last_twelve_months" optional="show" />
<field name="months_with_stock" optional="show" />
<field name="sales_count" optional="show" />
<field name="months_with_stock_sales_count" optional="show" />
</field>
</field>
</record>


<record id="view_warehouse_orderpoint_tree_editable_config" model="ir.ui.view">
<field name="model">stock.warehouse.orderpoint</field>
<field
Expand All @@ -22,6 +23,8 @@
<field name="route_id" position="before">
<field name="consumed_last_twelve_months" optional="show" />
<field name="months_with_stock" optional="show" />
<field name="sales_count" optional="show" />
<field name="months_with_stock_sales_count" optional="show" />
</field>
</field>
</record>
Expand Down

0 comments on commit 3581d83

Please sign in to comment.