Skip to Content
Menu
This question has been flagged
1 Reply
6423 Views

I'm very new on ODOO. I'm trying to validate the purchase orders VS a custom field (quantity permited by certain supplier).

I've created a module with the following:

models.py

from odoo import models, fields, api

class SupplierInfoInherited(models.Model):
    _inherit = 'product.supplierinfo'

quantity = fields.Integer(string='Quantity allowed for this supplier')

On view.xml:

<odoo>
<!--Inherit the supplier form view--> 
<record id="view_supplier_form_custom" model="ir.ui.view"> 
<field name="name">product.supplierinfo.form.inherited</field>
    <field name="model">product.supplierinfo</field> 
    <field name="inherit_id" ref="product.product_supplierinfo_form_view"/> 
    <field name="arch" type="xml"> 
        <xpath expr="//field[@name='product_id']" position="after"> 
            <field name="quantity"/>
        </xpath> 
    </field> 
</record>

Now i'm need get this value on purchases.order.line and validate that the quantity of products does not exceed the amount determined in the custom rule, using javascript/python at the moment of purchase. Any ideas? thanks

Avatar
Discard
Best Answer

To add quantity in purchase order line , you can overwrite following method:

_suggest_quantity()

You can add your custom field "quantity" instead of "min_qty", It will be set quantity in purchase order line when you select that product and vendor related to that product.

Your code will be like following :

from odoo import models, fields, api

class PurchaseOrde_line(models.Model):

    _inherit = 'purchase.order.line'

    def _suggest_quantity(self):

         if not self.product_id:

            return

         seller_min_qty = self.product_id.seller_ids.filtered(lambda r: r.name == self.order_id.partner_id).sorted(key=lambda r: r.quantity)

         if seller_min_qty:

             self.product_qty = seller_min_qty[0].quantity or 1.0

             self.product_uom = seller_min_qty[0].product_uom

        else:

             self.product_qty = 1.0

Avatar
Discard
Author

Thanks! you know how override the method for save the purchase? before save I can validate this, thanks again

Related Posts Replies Views Activity
0
Jan 16
3773
2
May 25
1901
3
Dec 24
5818
1
Jul 24
2725
1
Jun 24
1909