account_move.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, models
  4. class AccountMoveLine(models.Model):
  5. _inherit = 'account.move.line'
  6. def _sale_can_be_reinvoice(self):
  7. """ determine if the generated analytic line should be reinvoiced or not.
  8. For Expense flow, if the product has a 'reinvoice policy' and a Sales Order is set on the expense, then we will reinvoice the AAL
  9. """
  10. self.ensure_one()
  11. if self.expense_id: # expense flow is different from vendor bill reinvoice flow
  12. return self.expense_id.product_id.expense_policy in ['sales_price', 'cost'] and self.expense_id.sale_order_id
  13. return super(AccountMoveLine, self)._sale_can_be_reinvoice()
  14. def _sale_determine_order(self):
  15. """ For move lines created from expense, we override the normal behavior.
  16. Note: if no SO but an AA is given on the expense, we will determine anyway the SO from the AA, using the same
  17. mecanism as in Vendor Bills.
  18. """
  19. mapping_from_invoice = super(AccountMoveLine, self)._sale_determine_order()
  20. mapping_from_expense = {}
  21. for move_line in self.filtered(lambda move_line: move_line.expense_id):
  22. mapping_from_expense[move_line.id] = move_line.expense_id.sale_order_id or None
  23. mapping_from_invoice.update(mapping_from_expense)
  24. return mapping_from_invoice
  25. def _sale_prepare_sale_line_values(self, order, price):
  26. # Add expense quantity to sales order line and update the sales order price because it will be charged to the customer in the end.
  27. self.ensure_one()
  28. res = super()._sale_prepare_sale_line_values(order, price)
  29. if self.expense_id:
  30. res.update({'product_uom_qty': self.expense_id.quantity})
  31. return res