Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
3220 Zobrazení

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
Zrušit
Autor Nejlepší odpověď

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
Zrušit

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.

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
úno 25
1338
1
pro 24
1517
2
říj 24
12889
1
zář 22
3121
1
bře 22
4106