NeoVe
NeoVe

Reputation: 3897

Relating Custom module field - Products - OpenErp

I need to relate a field from a custom module to a button to be placed in the Purchase Order form of OpenErp.

When a product picking is confirmed this button will "discharge" the quantity of this product filled in the "quantity" field of my custom module.

For example:

class certificados_line(osv.osv):

    _name = 'certificados.line'
    _description = "Items del Certificado"


    def multi_a_b(self, cr, uid, ids, name, arg, context=None):
        res = {}
        for record in self.browse(cr, uid, ids,context):
            res[record.id] = record.Cantidad * record.Precio_Unitario_Declarado
        return res

    _columns = {
        'codigo_n' : fields.related(
                'product_id',
                'codigo_n',
                type='char',
                size=64,
                string='Codigo Arancelario',
                store=True,
                readonly=True,
                ),
        'product_id' : fields.many2one(
                'product.product',
                'Material',
                ),
        'Descripcion_Arancelaria' : fields.many2one(
                'product.category',
                'Descripcion Arancelaria',
                change_default=True,
                domain="[('type','=','normal')]",
                ), 
        'tec_esp': fields.related(
                'product_id',
                'tec_esp',
                type='char',
                size=64,
                string='Especificaciones tecnicas',
                store=True,
                readonly=True,
                ),
        'Cantidad' : fields.float(
                'Cantidad',
                ),
        'Unidad_de_Medida': fields.many2one(
                'product.uom',
                'Unidad de Medida',
                ),
        'Precio_Unitario_Declarado' : fields.float(
               'Precio Unitario Declarado',
                ),
        'Moneda' : fields.many2one(
                'res.currency',
                'Moneda',
                ),
        'Valor_En_Divisas' : fields.function(
                multi_a_b,
                type='integer',
                string='Valor En Divisas',
                ),
        'requisicion_id' : fields.many2one(
                'certificados.certificados',
                'Certificados de No Produccion',
                ondelete='cascade',
                ),
        'Cantidad_Consumida' : fields.related(
                'product_id',
                'outgoing_qty',
                type='float',
                string='Cantidad Consumida',
                store=True,
                readonly=True,
                ),
        'Cantidad_Disponible' : fields.related(
                'product_id',
                'qty_available',
                type='float',
                string='Cantidad Disponible',
                store=True,
                readonly=True,
                ),
    }   
certificados_line()

Here, Cantidad should be the field to be automatically related to the purchase order, I mean, in the "Request for Quotation" and "Purchase Order" in OpenErp, when the picking is confirmed the Product stock in the warehouse gets automatically updated, "product_qty".

I need to do the same but not with the stock or warehouse in OpenErp but just to this Cantidad field in my custom module, because some items could be bought and are managed from the warehouse and others from this module.

I've seen the buttons in the Purchase Order form, I could create a new one for this task, but my problem is, how to relate this field to the Purchase Orderin my custom module, while keeping the conventional relationship with stock?

For further understanding, it will not be an automatic update, just an independent update, depending on when this button is clicked or not.

I hope I've explained myself.

Thanks in advance.

Upvotes: 4

Views: 839

Answers (1)

Sinoj
Sinoj

Reputation: 416

I'm not sure I clearly understand your Question, but let me try to present you a generic approach.

First of all, you need an understanding of the concept of stock location and product stock in OpenERP.

Basic building block for stock in OpenERP is product transactions/ product moves. If you move product AAA from location XXX to location YYY, you are creasing the stock for AAA at YYY and the stock of AAA will be reduced at XXX. When you are purchasing a product, the product will be moved from "Supplier location" to your "stock location". When you are selling something, you are moving products from your "stock location" to "Customer location". So stock of a product at a particular location will be a summary of products moved in and moved out.

When ever you want to update a stock of a product in openERP, what you have to do is to make a stock move from "stock location" to other virtual locations (like customer location, inventory loss, production location etc)

Let me know your thoughts from this perspective and I'll update the answer to focus on a solution for you.

Upvotes: 1

Related Questions