Odoo Help


About stock management.

Zied Haffoudhi
on 3/28/16, 11:17 AM 800 views

Hi guys, I'm new here I hope if someone can help me with this.

I have 2 class :

class Purchase(models.Model):
    _name = 'tjara.purchase'
    name = fields.Char(string="Nom Achat", required=True)
    device = fields.Many2one('tjara.stock', ondelete='cascade', string="Device")
    number_product = fields.Integer(string="Number of product")

And :

class Stock(models.Model):
_name = 'tjara.stock'
name = fields.Char(string="Device Name", required=True)
number = fields.Integer(string="Number in stock")

How can I check if there are products in the stock for the current purchase ? (stock.number need to be > than purchase.number_product.)

And how can I decrement the number in stock automatically after every purchase ? (stock.number = stock.number - purchase.number_product)

Thanks a lot.

Zied Haffoudhi
On 3/29/16, 5:15 AM

Hi Michael,

Thanks for your answer. Actually I'm working on a new app, I need to do something by myself since I'm beginner as I said.

I didn't get the objective of the new variable 'inv_qty', Why I need to add this one ?! And what can I write here : 'product_id.??????'

inv_qty was meant to be the computed value of "inventory/stock quantity on hand". If you are a beginner I would suggest not rewriting two of the biggest most complicated modules in the system. However your idea of including the stock quantity on the purchase screen is a good one, and much more manageable. I would advise you create an addon module that just modifies the purchase module.

Michael Watchorn
on 3/29/16, 9:26 AM
Michael Watchorn
On 3/28/16, 9:18 PM

Are you using the default purchase and stock modules? From your question, what you are looking for is a computed field.

From the documentation:

Computed fields

Fields can be computed (instead of read straight from the database) using the compute parameter. It must assign the computed value to the field. If it uses the values of other fields, it should specify those fields using depends():

from openerp import api
inv_qty = fields.Float(compute='_compute_inv_qty')

def _compute_inv_qty(self):
    return product_id.??????(have to figure out what to return)

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/28/16, 11:17 AM
Seen: 800 times
Last updated: 3/29/16, 5:15 AM