diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/sale_expense/models/account_move.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/sale_expense/models/account_move.py')
| -rw-r--r-- | addons/sale_expense/models/account_move.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/addons/sale_expense/models/account_move.py b/addons/sale_expense/models/account_move.py new file mode 100644 index 00000000..c2e90b80 --- /dev/null +++ b/addons/sale_expense/models/account_move.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class AccountMoveLine(models.Model): + _inherit = 'account.move.line' + + def _sale_can_be_reinvoice(self): + """ determine if the generated analytic line should be reinvoiced or not. + 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 + """ + self.ensure_one() + if self.expense_id: # expense flow is different from vendor bill reinvoice flow + return self.expense_id.product_id.expense_policy in ['sales_price', 'cost'] and self.expense_id.sale_order_id + return super(AccountMoveLine, self)._sale_can_be_reinvoice() + + def _sale_determine_order(self): + """ For move lines created from expense, we override the normal behavior. + Note: if no SO but an AA is given on the expense, we will determine anyway the SO from the AA, using the same + mecanism as in Vendor Bills. + """ + mapping_from_invoice = super(AccountMoveLine, self)._sale_determine_order() + + mapping_from_expense = {} + for move_line in self.filtered(lambda move_line: move_line.expense_id): + mapping_from_expense[move_line.id] = move_line.expense_id.sale_order_id or None + + mapping_from_invoice.update(mapping_from_expense) + return mapping_from_invoice + + def _sale_prepare_sale_line_values(self, order, price): + # Add expense quantity to sales order line and update the sales order price because it will be charged to the customer in the end. + self.ensure_one() + res = super()._sale_prepare_sale_line_values(order, price) + if self.expense_id: + res.update({'product_uom_qty': self.expense_id.quantity}) + return res |
