Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
5369 Visualizzazioni

I want to generate a purchase order invoice from the information obtained from mrp. I want to get products from bill of materials(raw materials),price from product's cost price.Right now I have created a button for generating purchase order,it is only copying mrp invoice no and date created it is not entering the inside for loop and also I am not getting how to retrieve the current mrp id,I have hardcoded the id itself.This method is called when the button is pressed.

from openerp import models,api
class mrp_production(models.Model):
    _inherit = 'mrp.production'

    @api.multi
    def generate_purchase_order(self,supplier_id,pricelist_id,warehouse_id):
        purchase_obj = self.env['purchase.order']
        purchase_line_obj = self.env['purchase.order.line']
        warehouse_obj = self.env['stock.warehouse']

        warehouse = warehouse_obj.browse(warehouse_id)
        if not warehouse:
            return False
        if isinstance(warehouse, list):
            warehouse = warehouse[0]

        for order in self.browse(1):#how to remove this hardcoded id?
            vals = {}
            vals = purchase_obj.onchange_partner_id(supplier_id)
            vals['origin'] = order.name
            vals['partner_id'] = supplier_id
            vals['pricelist_id'] = pricelist_id
            vals['warehouse_id'] = warehouse_id
            vals['location_id'] = warehouse.lot_stock_id.id
            vals['date_order'] = order.date_planned
            purchase_id = purchase_obj.create(vals)

            for line in self.bom_id.bom_line_ids:
            #this for loop is not getting executed
                if not line.product_id:
                    continue

                line_vals = purchase_line_obj.onchange_product_id(self,pricelist_id,line.product_id.id,
                                                line.product_uom_qty, line.product_uom.id, supplier_id,
                                                date_planned=line.date_planned)['value']

                line_vals['product_id'] = line.product_id.id
                if not line_vals.get('price_unit', False):
                    line_vals['price_unit'] = line.product_id.list_price
                line_vals['product_uom'] = line.product_uom.id
                line_vals['product_uom_qty'] = 181.13
                line_vals['order_id'] = purchase_id
                purchase_line_obj.create(line_vals)

        return True

Avatar
Abbandona
Risposta migliore

Hello Bhanukiran,

As per new api we can access its fields and methods from directly using self because self it self is browsable record.

Example :

class account_invoice(models.Model):

    _name = "account.invoice"

    def test_function(self):

    for invoice in self:

        print invoice.number # It will print Number of all invoices


Hope this help.

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
dic 16
5133
6
ago 16
28855
4
apr 16
7292
6
nov 15
5662
1
mar 15
3612