OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Odoo 14, wrong compute probably or anything?

  • Thread starter Thread starter Ali Shidqie Al Faruqi
  • Start date Start date
A

Ali Shidqie Al Faruqi

Guest
I've started to learn Odoo by starting the version 14. I have an issues that I don't know why it doesn't showing. Because the other field are displaying.

What I wanted are inside the calendar view of Manufacturing (Manufacturing->Manufacture Orders->View Calendar) it able to show how many (quantity) products has been sold (Sale order Line), has been purchased (Purchase order line), and lastly how many stock in hand (As far as I know, it use stock.quant) by using custom module. The Sale Order and Purchase Order able to display the value from it. I use superuser for it.

For example:

Code:
WH/MO/00005
 Sunday, June 30, 2024
 18:08 - 19:08 (an hour)
Responsible :
OdooBot
Product :
Ali-A
Quantity To Produce :
50.00
Sale Order Quantity :
60.00
Purchase Order Quantity :
80.00
Stock on Hand :

My question is why the sale order and purchase order are showing, but the stock on Hand are not showing anything not even zero (0)? I just started using Odoo and learning Python. What could've gone wrong with the compute or do I make mistake putting the model for it? I have no clue so far. I provide the model and the views.

mrp_production.py

Code:
from odoo import models, fields, api

class MrpProduction(models.Model):
    _inherit = 'mrp.production'

    sale_order_quantity = fields.Float(string='Sale Order Quantity', compute='_compute_sale_order_quantity', store=True)
    purchase_order_quantity = fields.Float(string='Purchase Order Quantity', compute='_compute_purchase_order_quantity', store=True)
    stock_on_hand = fields.Float(string='Inventory Quantity', compute='_compute_stock_on_hand', store=True)

    @api.depends('product_id')
    def _compute_sale_order_quantity(self):
        for record in self:
            sale_orders = self.env['sale.order.line'].search([('product_id', '=', record.product_id.id)])
            record.sale_order_quantity = sum(line.product_qty for line in sale_orders)

    @api.depends('product_id')
    def _compute_purchase_order_quantity(self):
        for record in self:
            purchase_orders = self.env['purchase.order.line'].search([('product_id', '=', record.product_id.id)])
            record.purchase_order_quantity = sum(line.product_qty for line in purchase_orders)

    @api.depends('product_id')
    def _compute_stock_on_hand(self):
        for record in self:
            quants = self.env['stock.quant'].search([('product_id', '=', record.product_id.id)])
            record.stock_on_hand = sum(quant.quantity + quant.reserved_quantity for quant in quants)

views

Code:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
  <record id="mrp_custom" model="ir.ui.view">
    <field name="name">mrp.custom.calendar</field>
    <field name="model">mrp.production</field>
    <field name="inherit_id" ref="mrp.view_production_calendar"/>
    <field name="arch" type="xml">
      <xpath expr="//calendar" position="inside">
        <field name="sale_order_quantity"/>
        <field name="purchase_order_quantity"/>
        <field name="stock_on_hand"/>
      </xpath>
    </field>
  </record>
</odoo>

I try to put all the sale order, purchase order, and lastly stock in hand so I able to know how exactly quantity for a product have or how many stock left in the inventory. What I wanted is to be able to show like:

Code:
WH/MO/00005
 Sunday, June 30, 2024
 18:08 - 19:08 (an hour)
Responsible :
OdooBot
Product :
Ali-A
Quantity To Produce :
50.00
Sale Order Quantity :
60.00
Purchase Order Quantity :
80.00
Stock on Hand :
500,000.00 (because I put 500,000 inside the on hand after update quantity)
<p>I've started to learn Odoo by starting the version 14. I have an issues that I don't know why it doesn't showing. Because the other field are displaying.</p>
<p>What I wanted are inside the calendar view of Manufacturing (Manufacturing->Manufacture Orders->View Calendar) it able to show how many (quantity) products has been sold (Sale order Line), has been purchased (Purchase order line), and lastly how many stock in hand (As far as I know, it use stock.quant) by using custom module. The Sale Order and Purchase Order able to display the value from it. I use superuser for it.</p>
<p>For example:</p>
<pre><code>WH/MO/00005
Sunday, June 30, 2024
18:08 - 19:08 (an hour)
Responsible :
OdooBot
Product :
Ali-A
Quantity To Produce :
50.00
Sale Order Quantity :
60.00
Purchase Order Quantity :
80.00
Stock on Hand :
</code></pre>
<p>My question is why the sale order and purchase order are showing, but the stock on Hand are not showing anything not even zero (0)? I just started using Odoo and learning Python. What could've gone wrong with the compute or do I make mistake putting the model for it? I have no clue so far. I provide the model and the views.</p>
<p>mrp_production.py</p>
<pre><code>from odoo import models, fields, api

class MrpProduction(models.Model):
_inherit = 'mrp.production'

sale_order_quantity = fields.Float(string='Sale Order Quantity', compute='_compute_sale_order_quantity', store=True)
purchase_order_quantity = fields.Float(string='Purchase Order Quantity', compute='_compute_purchase_order_quantity', store=True)
stock_on_hand = fields.Float(string='Inventory Quantity', compute='_compute_stock_on_hand', store=True)

@api.depends('product_id')
def _compute_sale_order_quantity(self):
for record in self:
sale_orders = self.env['sale.order.line'].search([('product_id', '=', record.product_id.id)])
record.sale_order_quantity = sum(line.product_qty for line in sale_orders)

@api.depends('product_id')
def _compute_purchase_order_quantity(self):
for record in self:
purchase_orders = self.env['purchase.order.line'].search([('product_id', '=', record.product_id.id)])
record.purchase_order_quantity = sum(line.product_qty for line in purchase_orders)

@api.depends('product_id')
def _compute_stock_on_hand(self):
for record in self:
quants = self.env['stock.quant'].search([('product_id', '=', record.product_id.id)])
record.stock_on_hand = sum(quant.quantity + quant.reserved_quantity for quant in quants)

</code></pre>
<p>views</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="mrp_custom" model="ir.ui.view">
<field name="name">mrp.custom.calendar</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.view_production_calendar"/>
<field name="arch" type="xml">
<xpath expr="//calendar" position="inside">
<field name="sale_order_quantity"/>
<field name="purchase_order_quantity"/>
<field name="stock_on_hand"/>
</xpath>
</field>
</record>
</odoo>
</code></pre>
<p>I try to put all the sale order, purchase order, and lastly stock in hand so I able to know how exactly quantity for a product have or how many stock left in the inventory. What I wanted is to be able to show like:</p>
<pre><code>WH/MO/00005
Sunday, June 30, 2024
18:08 - 19:08 (an hour)
Responsible :
OdooBot
Product :
Ali-A
Quantity To Produce :
50.00
Sale Order Quantity :
60.00
Purchase Order Quantity :
80.00
Stock on Hand :
500,000.00 (because I put 500,000 inside the on hand after update quantity)
</code></pre>
 
Top