Help

0

create invoice through the wizard billing order of the sales order

Avatar
GiancaFTx

how to create invoice through the wizard billing order of the sales order. create invoice button (object: sale.advance.payment.inv), action: (create_invoices) and send a custom column from the sales order line to the invoice line.   but for some reason, the field is not copied.

new field of the invoice line  : price_unit2

odoo12: release

class sale_send_value(models.TransientModel):

_inherit = "sale.advance.payment.inv"

@api.multi

    def create_invoices(self):

        sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', []))

         if self.advance_payment_method == 'delivered':

            sale_orders.action_invoice_create()

        elif self.advance_payment_method == 'all':

            sale_orders.action_invoice_create(final=True)

        else:

            # Create deposit product if necessary

            if not self.product_id:

                vals = self._prepare_deposit_product()

                self.product_id = self.env['product.product'].create(vals)

                self.env['ir.config_parameter'].sudo().set_param('sale.default_deposit_product_id', self.product_id.id)

 

            sale_line_obj = self.env['sale.order.line']

            for order in sale_orders:

                if self.advance_payment_method == 'percentage':

                    amount = order.amount_untaxed * self.amount / 100

                else:

                    amount = self.amount

                if self.product_id.invoice_policy != 'order':

                    raise UserError(_('The product used to invoice a down payment should have an invoice policy set to "Ordered quantities". Please update your deposit product to be able to create a deposit invoice.'))

                if self.product_id.type != 'service':

                    raise UserError(_("The product used to invoice a down payment should be of type 'Service'. Please use another product or update this product."))

                taxes = self.product_id.taxes_id.filtered(lambda r: not order.company_id or r.company_id == order.company_id)

                if order.fiscal_position_id and taxes:

                    tax_ids = order.fiscal_position_id.map_tax(taxes, self.product_id, order.partner_shipping_id).ids

                else:

                    tax_ids = taxes.ids

                context = {'lang': order.partner_id.lang}

                analytic_tag_ids = []

                for line in order.order_line:

                    analytic_tag_ids = [(4, analytic_tag.id, None) for analytic_tag in line.analytic_tag_ids]

                so_line = sale_line_obj.create({

                    'name': _('Advance: %s') % (time.strftime('%m %Y'),),

                    'price_unit': amount,

                    'product_uom_qty': 0.0,

                    'order_id': order.id,

                    'discount': 0.0,

                    'product_uom': self.product_id.uom_id.id,

                    'product_id': self.product_id.id,

                    'analytic_tag_ids': analytic_tag_ids,

                    'tax_id': [(6, 0, tax_ids)],

                    'is_downpayment': True,

                    'price_unit2':100,

                })

                del context

                self._create_invoice(order, so_line, amount)

        if self._context.get('open_invoices', False):

            return sale_orders.action_view_invoice()

        return {'type': 'ir.actions.act_window_close'}

 

 


Avatar
Discard
1 Answer
0
Avatar
Chris TRINGHAM
Best Answer

Seems to me that the code you listed creates a downpayment line on the sales order (for a "Down payment" invoice).  You may have to look elsewhere for the invoice creation.


Avatar
Discard