Skip to Content
Menu
This question has been flagged
2 Replies
2483 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.

Avatar
Discard
Author Best Answer

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.??????'

Avatar
Discard

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.

Best Answer

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')

@api.depends('product_id')
def _compute_inv_qty(self):
    return product_id.??????(have to figure out what to return)
Avatar
Discard
Related Posts Replies Views Activity
1
Dec 24
114
2
Oct 24
2584
1
Sep 22
2183
1
Mar 22
2962
2
Mar 19
3815