You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
944 B

  1. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  2. from odoo import api, fields, models
  3. class SaleOrder(models.Model):
  4. _inherit = 'sale.order'
  5. contract_id = fields.Many2one(
  6. comodel_name="contract.contract",
  7. string="Contract"
  8. )
  9. @api.multi
  10. def action_confirm(self):
  11. res = super(SaleOrder, self).action_confirm()
  12. invoice_ids = self.env['account.invoice'].search([
  13. ('partner_id', '=', self.partner_id.id),
  14. ('old_contract_id', '=', self.contract_id.id),
  15. ('state', '=', 'draft')])
  16. for invoice_id in invoice_ids:
  17. for order_line in self.order_line:
  18. for invoice_line in invoice_id.invoice_line_ids:
  19. if order_line.product_id.id == invoice_line.product_id.id:
  20. invoice_line.quantity += order_line.product_uom_qty
  21. self.action_invoice_create()
  22. return res