[IMP] *: use get_fiscal_position and not property_account_position_id.

And adapt to get_fiscal_position changes

closes odoo/odoo#40336

Related: odoo/enterprise#6840
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
Victor Feyens
2019-11-20 14:42:07 +00:00
parent 81245528d1
commit 600d0707ae
12 changed files with 45 additions and 40 deletions
+1 -2
View File
@@ -325,9 +325,8 @@ class AccountMove(models.Model):
# Find the new fiscal position.
delivery_partner_id = self._get_invoice_delivery_partner_id()
new_fiscal_position_id = self.env['account.fiscal.position'].with_company(self.company_id).get_fiscal_position(
self.fiscal_position_id = self.env['account.fiscal.position'].with_company(self.company_id).get_fiscal_position(
self.partner_id.id, delivery_id=delivery_partner_id)
self.fiscal_position_id = self.env['account.fiscal.position'].browse(new_fiscal_position_id)
self._recompute_dynamic_lines()
if warning:
return {'warning': warning}
+1 -1
View File
@@ -64,7 +64,7 @@ class TestFiscalPosition(common.SavepointCase):
def test_10_fp_country(self):
def assert_fp(partner, expected_pos, message):
self.assertEqual(
self.fp.get_fiscal_position(partner.id),
self.fp.get_fiscal_position(partner.id).id,
expected_pos.id,
message)
+7 -7
View File
@@ -212,13 +212,12 @@ class PurchaseOrder(models.Model):
self.currency_id = self.partner_id.property_purchase_currency_id.id or self.env.company.currency_id.id
return {}
@api.onchange('fiscal_position_id')
@api.onchange('fiscal_position_id', 'company_id')
def _compute_tax_id(self):
"""
Trigger the recompute of the taxes if the fiscal position is changed on the PO.
"""
for order in self:
order.order_line._compute_tax_id()
self.order_line._compute_tax_id()
@api.onchange('partner_id')
def onchange_partner_id_warning(self):
@@ -518,10 +517,11 @@ class PurchaseOrderLine(models.Model):
def _compute_tax_id(self):
for line in self:
fpos = line.order_id.fiscal_position_id or line.order_id.partner_id.with_company(line.company_id).property_account_position_id
# If company_id is set, always filter taxes by the company
taxes = line.product_id.supplier_taxes_id.filtered(lambda r: not line.company_id or r.company_id == line.company_id)
line.taxes_id = fpos.map_tax(taxes, line.product_id, line.order_id.partner_id) if fpos else taxes
line = line.with_company(line.company_id)
fpos = line.order_id.fiscal_position_id or line.order_id.fiscal_position_id.get_fiscal_position(line.order_id.partner_id.id)
# filter taxes by company
taxes = line.product_id.supplier_taxes_id.filtered(lambda r: r.company_id == line.env.company)
line.taxes_id = fpos.map_tax(taxes, line.product_id, line.order_id.partner_id)
@api.depends('invoice_lines.move_id.state', 'invoice_lines.quantity')
def _compute_qty_invoiced(self):
@@ -24,7 +24,6 @@ class PurchaseOrder(models.Model):
FiscalPosition = self.env['account.fiscal.position']
fpos = FiscalPosition.with_company(self.company_id).get_fiscal_position(partner.id)
fpos = FiscalPosition.browse(fpos)
self.partner_id = partner.id
self.fiscal_position_id = fpos.id
+1 -1
View File
@@ -282,7 +282,7 @@ class StockRule(models.Model):
'origin': ', '.join(origins),
'payment_term_id': partner.with_company(company_id).property_supplier_payment_term_id.id,
'date_order': purchase_date,
'fiscal_position_id': fpos,
'fiscal_position_id': fpos.id,
'group_id': group
}
+21 -18
View File
@@ -644,22 +644,23 @@ class RepairLine(models.Model):
def onchange_product_id(self):
""" On change of product it sets product quantity, tax account, name,
uom of product, unit price and price subtotal. """
partner = self.repair_id.partner_id
pricelist = self.repair_id.pricelist_id
if not self.product_id or not self.product_uom_qty:
return
if self.product_id:
if partner:
self.name = self.product_id.with_context(lang=partner.lang).display_name
else:
self.name = self.product_id.display_name
if self.product_id.description_sale:
self.name += '\n' + self.product_id.description_sale
self.product_uom = self.product_id.uom_id.id
self = self.with_company(self.company_id)
partner = self.repair_id.partner_id
if partner:
self = self.with_context(lang=partner.lang)
product = self.product_id
self.name = product.display_name
if product.description_sale:
self.name += '\n' + product.description_sale
self.product_uom = product.uom_id.id
if self.type != 'remove':
if partner and self.product_id:
self.tax_id = partner.property_account_position_id.map_tax(self.product_id.taxes_id, self.product_id, partner).ids
if partner:
fpos = self.env['account.fiscal.position'].get_fiscal_position(partner.id)
self.tax_id = fpos.map_tax(self.product_id.taxes_id, self.product_id, partner)
warning = False
pricelist = self.repair_id.pricelist_id
if not pricelist:
warning = {
'title': _('No pricelist found.'),
@@ -723,16 +724,18 @@ class RepairFee(models.Model):
if not self.product_id:
return
self = self.with_company(self.company_id)
partner = self.repair_id.partner_id
pricelist = self.repair_id.pricelist_id
if partner and self.product_id:
self.tax_id = partner.property_account_position_id.map_tax(self.product_id.taxes_id, self.product_id, partner).ids
if self.product_id:
self.name = self.product_id.display_name
self.product_uom = self.product_id.uom_id.id
if self.product_id.description_sale:
self.name += '\n' + self.product_id.description_sale
fpos = self.env['account.fiscal.position'].get_fiscal_position(partner.id)
self.tax_id = fpos.map_tax(self.product_id.taxes_id, self.product_id, partner).ids
self.name = self.product_id.display_name
self.product_uom = self.product_id.uom_id.id
if self.product_id.description_sale:
self.name += '\n' + self.product_id.description_sale
warning = False
if not pricelist:
+1 -1
View File
@@ -173,7 +173,7 @@ class AccountMoveLine(models.Model):
last_so_line = self.env['sale.order.line'].search([('order_id', '=', order.id)], order='sequence desc', limit=1)
last_sequence = last_so_line.sequence + 1 if last_so_line else 100
fpos = order.fiscal_position_id or order.partner_id.property_account_position_id
fpos = order.fiscal_position_id or order.fiscal_position_id.get_fiscal_position(order.partner_id.id)
taxes = fpos.map_tax(self.product_id.taxes_id, self.product_id, order.partner_id)
return {
+5 -3
View File
@@ -489,6 +489,7 @@ class SaleOrder(models.Model):
a clean extension chain).
"""
self.ensure_one()
self = self.with_company(self.company_id)
journal = self.env['account.move'].with_company(self.company_id).with_context(default_type='out_invoice')._get_default_journal()
if not journal:
raise UserError(_('Please define an accounting sales journal for the company %s (%s).') % (self.company_id.name, self.company_id.id))
@@ -505,7 +506,7 @@ class SaleOrder(models.Model):
'team_id': self.team_id.id,
'partner_id': self.partner_invoice_id.id,
'partner_shipping_id': self.partner_shipping_id.id,
'fiscal_position_id': self.fiscal_position_id.id or self.partner_invoice_id.property_account_position_id.id,
'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id.get_fiscal_position(self.partner_invoice_id.id)).id,
'invoice_origin': self.name,
'invoice_payment_term_id': self.payment_term_id.id,
'invoice_payment_ref': self.reference,
@@ -1084,9 +1085,10 @@ class SaleOrderLine(models.Model):
def _compute_tax_id(self):
for line in self:
fpos = line.order_id.fiscal_position_id or line.order_id.partner_id.property_account_position_id
line = line.with_company(line.company_id)
fpos = line.order_id.fiscal_position_id or line.order_id.fiscal_position_id.get_fiscal_position(line.order_partner_id.id)
# If company_id is set, always filter taxes by the company
taxes = line.product_id.taxes_id.filtered(lambda r: not line.company_id or r.company_id == line.company_id)
taxes = line.product_id.taxes_id.filtered(lambda t: t.company_id == line.env.company)
line.tax_id = fpos.map_tax(taxes, line.product_id, line.order_id.partner_shipping_id)
@api.model
@@ -85,7 +85,7 @@ class SaleAdvancePaymentInv(models.TransientModel):
'invoice_user_id': order.user_id.id,
'narration': order.note,
'partner_id': order.partner_invoice_id.id,
'fiscal_position_id': order.fiscal_position_id.id or order.partner_id.property_account_position_id.id,
'fiscal_position_id': (order.fiscal_position_id or order.fiscal_position_id.get_fiscal_position(order.partner_id.id)).id,
'partner_shipping_id': order.partner_shipping_id.id,
'currency_id': order.pricelist_id.currency_id.id,
'invoice_payment_ref': order.client_order_ref,
+2 -1
View File
@@ -418,7 +418,8 @@ class SaleOrderLine(models.Model):
# as the product is the generic discount line.
# In case of a free product, retrieving the tax on the line instead of the product won't affect the behavior.
for line in reward_lines:
fpos = line.order_id.fiscal_position_id or line.order_id.partner_id.property_account_position_id
line = line.with_company(line.company_id)
fpos = line.order_id.fiscal_position_id or line.order_id.fiscal_position_id.get_fiscal_position(line.order_partner_id.id)
# If company_id is set, always filter taxes by the company
taxes = line.tax_id.filtered(lambda r: not line.company_id or r.company_id == line.company_id)
line.tax_id = fpos.map_tax(taxes, line.product_id, line.order_id.partner_shipping_id)
+2 -2
View File
@@ -177,7 +177,7 @@ class SaleOrderLine(models.Model):
self.ensure_one()
self = self.with_company(self.company_id)
partner_supplier = supplierinfo.name
fiscal_position_id = self.env['account.fiscal.position'].sudo().get_fiscal_position(partner_supplier.id)
fpos = self.env['account.fiscal.position'].sudo().get_fiscal_position(partner_supplier.id)
date_order = self._purchase_get_date_order(supplierinfo)
return {
'partner_id': partner_supplier.id,
@@ -188,7 +188,7 @@ class SaleOrderLine(models.Model):
'origin': self.order_id.name,
'payment_term_id': partner_supplier.property_supplier_payment_term_id.id,
'date_order': date_order,
'fiscal_position_id': fiscal_position_id,
'fiscal_position_id': fpos.id,
}
def _purchase_service_prepare_line_values(self, purchase_order, quantity=False):
+3 -2
View File
@@ -277,8 +277,9 @@ class ProductTemplate(models.Model):
company_id = current_website.company_id
product = self.env['product.product'].browse(combination_info['product_id']) or self
tax_display = self.env.user.has_group('account.group_show_line_subtotals_tax_excluded') and 'total_excluded' or 'total_included'
taxes = partner.property_account_position_id.map_tax(product.sudo().taxes_id.filtered(lambda x: x.company_id == company_id), product, partner)
tax_display = self.user_has_groups('account.group_show_line_subtotals_tax_excluded') and 'total_excluded' or 'total_included'
fpos = self.env['account.fiscal.position'].get_fiscal_position(partner.id)
taxes = fpos.map_tax(product.sudo().taxes_id.filtered(lambda x: x.company_id == company_id), product, partner)
# The list_price is always the price of one.
quantity_1 = 1