[FIX] purchase, sale: filter taxes properly when using a foreign VAT fiscal position
Before, when a foreign VAT fiscal position was used on a purchase order or sale order, no filtering was applied on the available taxes. We now make their behavior consistent with the invoices'. Part-of: odoo/odoo#79144
This commit is contained in:
@@ -122,6 +122,10 @@ class PurchaseOrder(models.Model):
|
||||
amount_total = fields.Monetary(string='Total', store=True, readonly=True, compute='_amount_all')
|
||||
|
||||
fiscal_position_id = fields.Many2one('account.fiscal.position', string='Fiscal Position', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
|
||||
tax_country_id = fields.Many2one(
|
||||
comodel_name='res.country',
|
||||
compute='_compute_tax_country_id',
|
||||
help="Technical field to filter the available taxes depending on the fiscal country and fiscal position.")
|
||||
payment_term_id = fields.Many2one('account.payment.term', 'Payment Terms', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
|
||||
incoterm_id = fields.Many2one('account.incoterms', 'Incoterm', states={'done': [('readonly', True)]}, help="International Commercial Terms are a series of predefined commercial terms used in international transactions.")
|
||||
|
||||
@@ -207,6 +211,14 @@ class PurchaseOrder(models.Model):
|
||||
tax_totals = account_move._get_tax_totals(order.partner_id, tax_lines_data, order.amount_total, order.amount_untaxed, order.currency_id)
|
||||
order.tax_totals_json = json.dumps(tax_totals)
|
||||
|
||||
@api.depends('company_id.account_fiscal_country_id', 'fiscal_position_id.country_id', 'fiscal_position_id.foreign_vat')
|
||||
def _compute_tax_country_id(self):
|
||||
for record in self:
|
||||
if record.fiscal_position_id.foreign_vat:
|
||||
record.tax_country_id = record.fiscal_position_id.country_id
|
||||
else:
|
||||
record.tax_country_id = record.company_id.account_fiscal_country_id
|
||||
|
||||
@api.onchange('date_planned')
|
||||
def onchange_date_planned(self):
|
||||
if self.date_planned:
|
||||
|
||||
@@ -197,7 +197,7 @@
|
||||
<span>Ask confirmation</span>
|
||||
<div class="o_row oe_inline" attrs="{'invisible': [('receipt_reminder_email', '=', False)]}">
|
||||
<field name="reminder_date_before_receipt" class="oe_inline"/>
|
||||
day(s) before
|
||||
day(s) before
|
||||
<widget name='toaster_button' button_name="send_reminder_preview" title="Preview the reminder email by sending it to yourself." attrs="{'invisible': [('id', '=', False)]}"/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -205,6 +205,7 @@
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Products" name="products">
|
||||
<field name="tax_country_id" invisible="1"/>
|
||||
<field name="order_line"
|
||||
widget="section_and_note_one2many"
|
||||
mode="tree,kanban"
|
||||
@@ -249,7 +250,7 @@
|
||||
<field name="product_packaging_qty" attrs="{'invisible': ['|', ('product_id', '=', False), ('product_packaging_id', '=', False)]}" groups="product.group_stock_packaging" optional="show"/>
|
||||
<field name="product_packaging_id" attrs="{'invisible': [('product_id', '=', False)]}" context="{'default_product_id': product_id, 'tree_view_ref':'product.product_packaging_tree_view', 'form_view_ref':'product.product_packaging_form_view'}" groups="product.group_stock_packaging" optional="show"/>
|
||||
<field name="price_unit" attrs="{'readonly': [('qty_invoiced', '!=', 0)]}"/>
|
||||
<field name="taxes_id" widget="many2many_tags" domain="[('type_tax_use','=','purchase'), ('company_id', '=', parent.company_id)]" context="{'default_type_tax_use': 'purchase', 'search_view_ref': 'account.account_tax_view_search'}" options="{'no_create': True}" optional="show"/>
|
||||
<field name="taxes_id" widget="many2many_tags" domain="[('type_tax_use','=','purchase'), ('company_id', '=', parent.company_id), ('country_id', '=', parent.tax_country_id)]" context="{'default_type_tax_use': 'purchase', 'search_view_ref': 'account.account_tax_view_search'}" options="{'no_create': True}" optional="show"/>
|
||||
<field name="price_subtotal" widget="monetary"/>
|
||||
</tree>
|
||||
<form string="Purchase Order Line">
|
||||
@@ -273,7 +274,7 @@
|
||||
<field name="qty_invoiced" string="Billed Quantity" attrs="{'invisible': [('parent.state', 'not in', ('purchase', 'done'))]}"/>
|
||||
<field name="product_packaging_id" attrs="{'invisible': [('product_id', '=', False)]}" context="{'default_product_id': product_id, 'tree_view_ref':'product.product_packaging_tree_view', 'form_view_ref':'product.product_packaging_form_view'}" groups="product.group_stock_packaging" />
|
||||
<field name="price_unit"/>
|
||||
<field name="taxes_id" widget="many2many_tags" domain="[('type_tax_use', '=', 'purchase'), ('company_id', '=', parent.company_id)]" options="{'no_create': True}"/>
|
||||
<field name="taxes_id" widget="many2many_tags" domain="[('type_tax_use', '=', 'purchase'), ('company_id', '=', parent.company_id), ('country_id', '=', parent.tax_country_id)]" options="{'no_create': True}"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="date_planned" widget="date" attrs="{'required': [('display_type', '=', False)]}"/>
|
||||
@@ -533,7 +534,7 @@
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- Unfortunately we want the purchase kpis table to only show up in some list views,
|
||||
so we have to duplicate code to support both view versions -->
|
||||
<record id="purchase_order_kpis_tree" model="ir.ui.view">
|
||||
@@ -541,8 +542,8 @@
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="priority" eval="10"/>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Purchase Order" decoration-info="state in ['draft', 'sent']"
|
||||
decoration-muted="state == 'cancel'" decoration-bf="message_unread==True"
|
||||
<tree string="Purchase Order" decoration-info="state in ['draft', 'sent']"
|
||||
decoration-muted="state == 'cancel'" decoration-bf="message_unread==True"
|
||||
class="o_purchase_order" js_class="purchase_list_dashboard" sample="1">
|
||||
<header>
|
||||
<button name="action_create_invoice" type="object" string="Create Bills"/>
|
||||
|
||||
@@ -244,6 +244,10 @@ class SaleOrder(models.Model):
|
||||
domain="[('company_id', '=', company_id)]", check_company=True,
|
||||
help="Fiscal positions are used to adapt taxes and accounts for particular customers or sales orders/invoices."
|
||||
"The default value comes from the customer.")
|
||||
tax_country_id = fields.Many2one(
|
||||
comodel_name='res.country',
|
||||
compute='_compute_tax_country_id',
|
||||
help="Technical field to filter the available taxes depending on the fiscal country and fiscal position.")
|
||||
company_id = fields.Many2one('res.company', 'Company', required=True, index=True, default=lambda self: self.env.company)
|
||||
team_id = fields.Many2one(
|
||||
'crm.team', 'Sales Team',
|
||||
@@ -363,6 +367,14 @@ class SaleOrder(models.Model):
|
||||
for record in self:
|
||||
record.type_name = _('Quotation') if record.state in ('draft', 'sent', 'cancel') else _('Sales Order')
|
||||
|
||||
@api.depends('company_id.account_fiscal_country_id', 'fiscal_position_id.country_id', 'fiscal_position_id.foreign_vat')
|
||||
def _compute_tax_country_id(self):
|
||||
for record in self:
|
||||
if record.fiscal_position_id.foreign_vat:
|
||||
record.tax_country_id = record.fiscal_position_id.country_id
|
||||
else:
|
||||
record.tax_country_id = record.company_id.account_fiscal_country_id
|
||||
|
||||
@api.ondelete(at_uninstall=False)
|
||||
def _unlink_except_draft_or_cancel(self):
|
||||
for order in self:
|
||||
|
||||
@@ -343,6 +343,7 @@
|
||||
attrs="{'invisible': ['|', ('show_update_pricelist', '=', False), ('state', 'in', ['sale', 'done','cancel'])]}"/>
|
||||
</div>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
<field name="tax_country_id" invisible="1"/>
|
||||
<field name="payment_term_id" options="{'no_open':True,'no_create': True}"/>
|
||||
</group>
|
||||
</group>
|
||||
@@ -409,7 +410,7 @@
|
||||
</div>
|
||||
<field name="product_packaging_id" attrs="{'invisible': [('product_id', '=', False)]}" context="{'default_product_id': product_id, 'tree_view_ref':'product.product_packaging_tree_view', 'form_view_ref':'product.product_packaging_form_view'}" groups="product.group_stock_packaging" />
|
||||
<field name="price_unit"/>
|
||||
<field name="tax_id" widget="many2many_tags" options="{'no_create': True}" context="{'search_view_ref': 'account.account_tax_view_search'}" domain="[('type_tax_use','=','sale'),('company_id','=',parent.company_id)]"
|
||||
<field name="tax_id" widget="many2many_tags" options="{'no_create': True}" context="{'search_view_ref': 'account.account_tax_view_search'}" domain="[('type_tax_use','=','sale'), ('company_id','=',parent.company_id), ('country_id', '=', parent.tax_country_id)]"
|
||||
attrs="{'readonly': [('qty_invoiced', '>', 0)]}"/>
|
||||
<label for="discount" groups="product.group_discount_per_so_line"/>
|
||||
<div name="discount" groups="product.group_discount_per_so_line">
|
||||
@@ -566,7 +567,7 @@
|
||||
name="tax_id"
|
||||
widget="many2many_tags"
|
||||
options="{'no_create': True}"
|
||||
domain="[('type_tax_use','=','sale'),('company_id','=',parent.company_id)]"
|
||||
domain="[('type_tax_use','=','sale'),('company_id','=',parent.company_id), ('country_id', '=', parent.tax_country_id)]"
|
||||
attrs="{'readonly': [('qty_invoiced', '>', 0)]}"
|
||||
optional="show"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user