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

Hey, I'm new to Odoo. I need to send 100s of invoices that are either for product A or product A+B to 100s of customers. I was hoping I could make an automation in the CRM module so that when I change an opportunity to stage X in the CRM -> create and send invoice to customer associated with the opportunity. If my custom property checkbox is left unchecked, then invoice with item A should be sent, and if checked, invoice with products A+B should be sent. Prices are constant for both products so the outgoing invoices are always one of two amounts (no customisation needed). 


How might I go about doing this? In Automation Rules, the Trigger seems straight forward, but the Action not so much...


Thank you

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Steps:

Go to Settings → Technical → Automation → Automated Actions.

Create a new one:

Model = CRM Lead

Trigger = On Update

Condition = stage_id == 'X'

Action to do: Execute Python Code.

Code:

# This runs in the context of crm.lead record(s)

for lead in records:

    partner = lead.partner_id

    if not partner:

        continue


    # Decide which products to add

    product_ids = []

    if lead.x_my_checkbox:  # your custom field

        product_ids = [env.ref('your_module.product_a').id,

                       env.ref('your_module.product_b').id]

    else:

        product_ids = [env.ref('your_module.product_a').id]


    # Create invoice (draft)

    invoice = env['account.move'].create({

        'move_type': 'out_invoice',

        'partner_id': partner.id,

        'invoice_line_ids': [

            (0, 0, {

                'product_id': pid,

                'quantity': 1,

                'price_unit': env['product.product'].browse(pid).lst_price,

            }) for pid in product_ids

        ]

    })


    # Post and send by email

    invoice.action_post()

    template = env.ref('account.email_template_edi_invoice')

    invoice.message_post_with_template(template.id)


Hope it helps.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 8 24
2215
1
thg 11 23
3623
0
thg 5 20
3180
2
thg 8 25
1596
2
thg 12 24
1619