Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
5117 Представления

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




Аватар
Отменить
Автор

thank you @Abdullah. 

Лучший ответ

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

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
июн. 23
2400
0
нояб. 20
3852
1
нояб. 21
3746
3
сент. 21
4945
4
мая 21
28848