Odoo Help

Welcome!

This community 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.

0

About stock management.

By
Zied Haffoudhi
on 3/28/16, 11:17 AM 370 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.

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

@api.depends('product_id')
def _compute_inv_qty(self):
    return product_id.??????(have to figure out what to return)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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