Skip to Content
Menu
This question has been flagged
2 Replies
4041 Views

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




Avatar
Discard
Author

thank you @Abdullah. 

Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 23
1536
0
Nov 20
2989
1
Nov 21
2983
3
Sep 21
4118
4
May 21
27490