Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
5080 Vizualizări

Hi,


 I have added a custom field like "custom_field" in my purchse.order.line and then i have added the same field in "account.move.line" which is used at Bill line. 


Now i want when i client the "Create Bill" button on my purchase order it should copy this field as well from purchase.order.line to account.move.line. Below is the core code on 'purchase.order. model. 


Please guide me how i can do this. thank you


def action_view_invoice(self):

        '''

        This function returns an action that display existing vendor bills of given purchase order ids.

        When only one found, show the vendor bill immediately.

        '''

        action = self.env.ref('account.action_move_in_invoice_type')

        result = action.read()[0]

        create_bill = self.env.context.get('create_bill', False)

        # override the context to get rid of the default filtering

        result['context'] = {

            'default_type': 'in_invoice',

            'default_company_id': self.company_id.id,

            'default_purchase_id': self.id,

        }

        # Invoice_ids may be filtered depending on the user. To ensure we get all

        # invoices related to the purchase order, we read them in sudo to fill the

        # cache.

        self.sudo () ._ read (['invoice_ids'])

        # choose the view_mode accordingly

        if len (self.invoice_ids)> 1 and not create_bill:

            result ['domain'] = "[('id', 'in'," + str (self.invoice_ids.ids) + ")]"

        else:

            res = self.env.ref ('account.view_move_form', False)

            form_view = [(res and res.id or False, 'form')]

            if 'views' in result:

                result ['views'] = form_view + [(state, view) for state, view in action ['views'] if view! = 'form']

            else:

                result ['views'] = form_view

            # Do not set an invoice_id if we want to create a new bill.

            if not create_bill:

                result ['res_id'] = self.invoice_ids.id or False

        result ['context'] ['default_invoice_origin'] = self.name

        result ['context'] ['default_ref'] = self.partner_ref

        return result




Imagine profil
Abandonează
Autor

thank you @Abdullah. 

Cel mai bun răspuns

You have a function name def _prepare_account_move_line in purchase.order.line,, inherit it and pass your valiue in it like

return{

'your_custom_field_in_invoice_line' : self.your_custom_field_in_purchase_order_line

}

Hope it helps. Thanks

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
iun. 23
2377
0
nov. 20
3810
1
nov. 21
3722
3
sept. 21
4911
4
mai 21
28793