diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2024-05-30 18:04:00 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2024-05-30 18:04:00 +0700 |
| commit | 1e9824d861f2208e1beb477ea8028cd007ecbd89 (patch) | |
| tree | 335f7f5324d92216dac1bdcba6edf4f4b779581d /fixco_custom | |
| parent | 89ff021709e23d2adefd08298c49be8a7eccf21a (diff) | |
add api create invoice
Diffstat (limited to 'fixco_custom')
| -rw-r--r-- | fixco_custom/models/sale.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py index 6c49ac8..ceea0ab 100644 --- a/fixco_custom/models/sale.py +++ b/fixco_custom/models/sale.py @@ -1,7 +1,41 @@ -from odoo import models, fields, api +from odoo import api, fields, models, _ +from odoo.exceptions import UserError class SaleOrder(models.Model): _inherit = "sale.order" carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method') + + def api_create_invoices(self, sale_order_id): + sale_orders = self.env['sale.order'].search([('id', '=', sale_order_id)]) + + # if self.advance_payment_method == 'delivered': + sale_orders._create_invoices(final=False) + # 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: + # amount, name = self._get_advance_details(order) + # + # 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) + # tax_ids = order.fiscal_position_id.map_tax(taxes, self.product_id, order.partner_shipping_id).ids + # 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_values = self._prepare_so_line(order, analytic_tag_ids, tax_ids, amount) + # so_line = sale_line_obj.create(so_line_values) + # 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'}
\ No newline at end of file |
