Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
5090 Lượt xem

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




Ảnh đại diện
Huỷ bỏ
Tác giả

thank you @Abdullah. 

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 23
2388
0
thg 11 20
3821
1
thg 11 21
3730
3
thg 9 21
4919
4
thg 5 21
28809