summaryrefslogtreecommitdiff
path: root/addons/point_of_sale/models/account_move.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/point_of_sale/models/account_move.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/point_of_sale/models/account_move.py')
-rw-r--r--addons/point_of_sale/models/account_move.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/addons/point_of_sale/models/account_move.py b/addons/point_of_sale/models/account_move.py
new file mode 100644
index 00000000..396c3d11
--- /dev/null
+++ b/addons/point_of_sale/models/account_move.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models, api
+
+
+class AccountMove(models.Model):
+ _inherit = 'account.move'
+
+ pos_order_ids = fields.One2many('pos.order', 'account_move')
+
+ def _stock_account_get_last_step_stock_moves(self):
+ stock_moves = super(AccountMove, self)._stock_account_get_last_step_stock_moves()
+ for invoice in self.filtered(lambda x: x.move_type == 'out_invoice'):
+ stock_moves += invoice.sudo().mapped('pos_order_ids.picking_ids.move_lines').filtered(lambda x: x.state == 'done' and x.location_dest_id.usage == 'customer')
+ for invoice in self.filtered(lambda x: x.move_type == 'out_refund'):
+ stock_moves += invoice.sudo().mapped('pos_order_ids.picking_ids.move_lines').filtered(lambda x: x.state == 'done' and x.location_id.usage == 'customer')
+ return stock_moves
+
+
+class AccountMoveLine(models.Model):
+ _inherit = 'account.move.line'
+
+ def _stock_account_get_anglo_saxon_price_unit(self):
+ self.ensure_one()
+ if not self.product_id:
+ return self.price_unit
+ price_unit = super(AccountMoveLine, self)._stock_account_get_anglo_saxon_price_unit()
+ order = self.move_id.pos_order_ids
+ if order:
+ price_unit = order._get_pos_anglo_saxon_price_unit(self.product_id, self.move_id.partner_id.id, self.quantity)
+ return price_unit
+
+ def _get_refund_tax_audit_condition(self, aml):
+ # Overridden so that the returns can be detected as credit notes by the tax audit computation
+ rslt = super()._get_refund_tax_audit_condition(aml)
+
+ if aml.move_id.is_invoice():
+ # We don't need to check the pos orders for this move line if an invoice
+ # is linked to it ; we know that the invoice type tells us whether it's a refund
+ return rslt
+
+ pos_orders_count = self.env['pos.order'].search_count([('account_move', '=', aml.move_id.id)])
+ return rslt or (pos_orders_count and aml.debit > 0)