[IMP] account,sale: move partner_shipping_id field from sale to account

The computation of 'partner_shipping_id' is now done using a 'compute' instead of 'onchange'.

task-2601934

closes odoo/odoo#78449

Related: odoo/enterprise#22098
Related: odoo/upgrade#3000
Signed-off-by: Laurent Smet <las@odoo.com>
This commit is contained in:
Camille Spiritus
2021-12-14 14:47:25 +00:00
committed by Laurent Smet
parent 298c23f048
commit 3732aea4b8
22 changed files with 94 additions and 99 deletions
+31 -8
View File
@@ -193,6 +193,15 @@ class AccountMove(models.Model):
country_code = fields.Char(related='company_id.account_fiscal_country_id.code', readonly=True)
user_id = fields.Many2one(string='User', related='invoice_user_id',
help='Technical field used to fit the generic behavior in mail templates.')
partner_shipping_id = fields.Many2one(
comodel_name='res.partner',
string='Delivery Address',
readonly=False,
store=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
help="Delivery address for current invoice.",
compute='_compute_partner_shipping_id',
)
is_move_sent = fields.Boolean(
readonly=True,
default=False,
@@ -502,7 +511,7 @@ class AccountMove(models.Model):
self.partner_bank_id = bank_ids and bank_ids[0]
# Find the new fiscal position.
delivery_partner = self.env['res.partner'].browse(self._get_invoice_delivery_partner_id())
delivery_partner = self.partner_shipping_id
self.fiscal_position_id = self.env['account.fiscal.position']._get_fiscal_position(
self.partner_id, delivery=delivery_partner)
self._recompute_dynamic_lines()
@@ -591,6 +600,18 @@ class AccountMove(models.Model):
move._recompute_dynamic_lines()
@api.onchange('partner_shipping_id', 'company_id')
def _onchange_partner_shipping_id(self):
"""
Trigger the change of fiscal position when the shipping address is modified.
"""
fiscal_position = self.env['account.fiscal.position']\
.with_company(self.company_id)\
._get_fiscal_position(self.partner_id, delivery=self.partner_shipping_id)
if fiscal_position:
self.fiscal_position_id = fiscal_position
@api.model
def _get_tax_grouping_key_from_tax_line(self, tax_line):
''' Create the dictionary based on a tax line that will be used as key to group taxes together.
@@ -1131,6 +1152,15 @@ class AccountMove(models.Model):
# COMPUTE METHODS
# -------------------------------------------------------------------------
@api.depends('partner_id')
def _compute_partner_shipping_id(self):
for move in self:
if move.is_invoice(include_receipts=True):
addr = move.partner_id.address_get(['delivery'])
move.partner_shipping_id = addr and addr.get('delivery')
else:
move.partner_shipping_id = False
@api.depends('company_id', 'invoice_filter_type_domain')
def _compute_suitable_journal_ids(self):
for m in self:
@@ -2547,13 +2577,6 @@ class AccountMove(models.Model):
name += self.name
return name + (show_ref and self.ref and ' (%s%s)' % (self.ref[:50], '...' if len(self.ref) > 50 else '') or '')
def _get_invoice_delivery_partner_id(self):
''' Hook allowing to retrieve the right delivery address depending of installed modules.
:return: A res.partner record's id representing the delivery address.
'''
self.ensure_one()
return self.partner_id.address_get(['delivery'])['delivery']
def _get_reconciled_payments(self):
"""Helper used to retrieve the reconciled payments on this journal entry"""
reconciled_lines = self.line_ids.filtered(lambda line: line.account_id.user_type_id.type in ('receivable', 'payable'))
@@ -145,6 +145,9 @@ class ResConfigSettings(models.TransientModel):
# Technical field to hide country specific fields from accounting configuration
country_code = fields.Char(related='company_id.account_fiscal_country_id.code', readonly=True)
# Allows for the use of a different delivery address
group_sale_delivery_address = fields.Boolean("Customer Addresses", implied_group='account.group_delivery_invoice_address')
def set_values(self):
super(ResConfigSettings, self).set_values()
# install a chart of accounts for the given company (if required)
@@ -33,6 +33,11 @@
<field name="sequence">7</field>
</record>
<record id="group_delivery_invoice_address" model="res.groups">
<field name="name">Delivery Address</field>
<field name="category_id" ref="base.module_category_hidden"/>
</record>
<record id="group_show_line_subtotals_tax_excluded" model="res.groups">
<field name="name">Tax display B2B</field>
<field name="comment">Show line subtotals without taxes (B2B)</field>
@@ -775,6 +775,9 @@
'show_address': 1, 'default_is_company': True, 'show_vat': True}"
options='{"always_reload": True, "no_quick_create": True}'
attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}"/>
<field name="partner_shipping_id"
groups="account.group_delivery_invoice_address"
attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund', 'out_receipt'))], 'readonly': [('state', '!=', 'draft')]}"/>
<label for="ref" string="Bill Reference"
attrs="{'invisible':[('move_type', 'not in', ('in_invoice', 'in_receipt', 'in_refund'))]}" />
<field name="ref" nolabel="1" attrs="{'invisible':[('move_type', 'not in', ('in_invoice', 'in_receipt', 'in_refund'))]}" />
+10 -1
View File
@@ -5,8 +5,17 @@
<t t-call="web.external_layout">
<t t-set="o" t-value="o.with_context(lang=lang)" />
<t t-set="forced_vat" t-value="o.fiscal_position_id.foreign_vat"/> <!-- So that it appears in the footer of the report instead of the company VAT if it's set -->
<t t-if="o.partner_shipping_id and (o.partner_shipping_id != o.partner_id)">
<t t-set="information_block">
<div groups="account.group_delivery_invoice_address" name="shipping_address_block">
<strong>Shipping Address:</strong>
<div t-field="o.partner_shipping_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}'/>
</div>
</t>
</t>
<div t-field="o.partner_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}' groups="account.group_delivery_invoice_address"/>
<t t-set="address">
<address t-field="o.partner_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}' />
<address t-field="o.partner_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}' groups="!account.group_delivery_invoice_address"/>
<div t-if="o.partner_id.vat" class="mt16">
<t t-if="o.company_id.account_fiscal_country_id.vat_label" t-esc="o.company_id.account_fiscal_country_id.vat_label" id="inv_tax_id_label"/>
<t t-else="">Tax ID</t>: <span t-field="o.partner_id.vat"/></div>
@@ -204,6 +204,18 @@
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box" id="invoice_delivery_addresses">
<div class="o_setting_left_pane">
<field name="group_sale_delivery_address"/>
</div>
<div class="o_setting_right_pane">
<label for="group_sale_delivery_address"/>
<a href="https://www.odoo.com/documentation/15.0/applications/sales/sales/send_quotations/different_addresses.html" title="Documentation" class="o_doc_link" target="_blank"></a>
<div class="text-muted">
Select specific invoice and delivery addresses
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box" id="line_subtotals">
<div class="o_setting_left_pane">
</div>
@@ -165,7 +165,7 @@
<!-- Delivery. Don't make a dependency with sale only for one field. -->
<ram:ApplicableHeaderTradeDelivery>
<ram:ShipToTradeParty
t-if="'partner_shipping_id' in record._fields and record.partner_shipping_id">
t-if="record.partner_shipping_id">
<t t-call="account_edi_facturx.account_invoice_partner_facturx_export">
<t t-set="partner" t-value="record.partner_shipping_id"/>
</t>
@@ -122,7 +122,15 @@ class TestAccountEdiFacturx(AccountEdiTestCommon):
<IssuerAssignedID>INV/2017/00001: INV/2017/00001</IssuerAssignedID>
</BuyerOrderReferencedDocument>
</ApplicableHeaderTradeAgreement>
<ApplicableHeaderTradeDelivery/>
<ApplicableHeaderTradeDelivery>
<ShipToTradeParty>
<Name>partner_b</Name>
<DefinedTradeContact>
<PersonName>partner_b</PersonName>
</DefinedTradeContact>
<PostalTradeAddress/>
</ShipToTradeParty>
</ApplicableHeaderTradeDelivery>
<ApplicableHeaderTradeSettlement>
<ApplicableTradeTax>
<CalculatedAmount currencyID="Gol">220.000</CalculatedAmount>
@@ -7,10 +7,10 @@
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='vat']" position="after">
<field name="l10n_in_shipping_gstin" groups="sale.group_delivery_invoice_address" attrs="{'invisible': ['|',('type', '!=', 'delivery'),('parent_id', '=', False)]}"/>
<field name="l10n_in_shipping_gstin" groups="account.group_delivery_invoice_address" attrs="{'invisible': ['|',('type', '!=', 'delivery'),('parent_id', '=', False)]}"/>
</xpath>
<xpath expr="//field[@name='child_ids']/form//field[@name='comment']" position="before">
<field name="l10n_in_shipping_gstin" groups="sale.group_delivery_invoice_address" attrs="{'invisible': [('type', '!=', 'delivery')]}"/>
<field name="l10n_in_shipping_gstin" groups="account.group_delivery_invoice_address" attrs="{'invisible': [('type', '!=', 'delivery')]}"/>
</xpath>
</field>
</record>
+2 -2
View File
@@ -82,7 +82,7 @@
<field name="product_uom" groups="uom.group_uom"/>
</div>
<field name="partner_id" widget="res_partner_many2one" attrs="{'required':[('invoice_method','!=','none')]}" context="{'res_partner_search_mode': 'customer', 'show_vat': True}"/>
<field name="address_id" groups="sale.group_delivery_invoice_address"/>
<field name="address_id" groups="account.group_delivery_invoice_address"/>
<field name="sale_order_id"/>
<field name="user_id" domain="[('share', '=', False)]"/>
</group>
@@ -92,7 +92,7 @@
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="guarantee_limit"/>
<field name="invoice_method"/>
<field name="partner_invoice_id" attrs="{'invisible':[('invoice_method','=', 'none')],'required':[('invoice_method','!=','none')]}" groups="sale.group_delivery_invoice_address"/>
<field name="partner_invoice_id" attrs="{'invisible':[('invoice_method','=', 'none')],'required':[('invoice_method','!=','none')]}" groups="account.group_delivery_invoice_address"/>
<field name="pricelist_id" groups="product.group_product_pricelist" context="{'product_id':product_id}" attrs="{'invisible':[('invoice_method','=', 'none')]}"/>
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': True}"/>
<field name="currency_id" invisible="1"/>
-1
View File
@@ -17,7 +17,6 @@ This module contains all the common features of Sales Management and eCommerce.
'report/sale_report.xml',
'report/sale_report_views.xml',
'report/sale_report_templates.xml',
'report/invoice_report_templates.xml',
'report/report_all_channels_sales_views.xml',
'data/ir_sequence_data.xml',
'data/mail_data_various.xml',
+3 -26
View File
@@ -18,13 +18,6 @@ class AccountMove(models.Model):
compute='_compute_team_id', store=True, readonly=False,
ondelete="set null", tracking=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
partner_shipping_id = fields.Many2one(
'res.partner',
string='Delivery Address',
readonly=True,
states={'draft': [('readonly', False)]},
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
help="Delivery address for current invoice.")
# UTMs - enforcing the fact that we want to 'set null' when relation is unlinked
campaign_id = fields.Many2one(ondelete='set null')
@@ -39,9 +32,9 @@ class AccountMove(models.Model):
def _compute_fiscal_position_id(self):
# Trigger the change of fiscal position when the shipping address is modified.
for move in self:
delivery_partner = self.env['res.partner'].browse(move._get_invoice_delivery_partner_id())
fiscal_position = self.env['account.fiscal.position'].with_company(
move.company_id)._get_fiscal_position(move.partner_id, delivery=delivery_partner)
fiscal_position = self.env['account.fiscal.position']\
.with_company(move.company_id)\
._get_fiscal_position(move.partner_id, delivery=move.partner_shipping_id)
if fiscal_position:
move.fiscal_position_id = fiscal_position
@@ -52,17 +45,6 @@ class AccountMove(models.Model):
downpayment_lines.unlink()
return res
@api.onchange('partner_id')
def _onchange_partner_id(self):
# OVERRIDE
# Recompute 'partner_shipping_id' based on 'partner_id'.
addr = self.partner_id.address_get(['delivery'])
self.partner_shipping_id = addr and addr.get('delivery')
res = super(AccountMove, self)._onchange_partner_id()
return res
@api.depends('invoice_user_id')
def _compute_team_id(self):
for move in self:
@@ -127,8 +109,3 @@ class AccountMove(models.Model):
for (order, name) in todo:
order.message_post(body=_("Invoice %s paid", name))
return res
def _get_invoice_delivery_partner_id(self):
# OVERRIDE
self.ensure_one()
return self.partner_shipping_id.id or super(AccountMove, self)._get_invoice_delivery_partner_id()
@@ -14,7 +14,6 @@ class ResConfigSettings(models.TransientModel):
group_warning_sale = fields.Boolean("Sale Order Warnings", implied_group='sale.group_warning_sale')
portal_confirmation_sign = fields.Boolean(related='company_id.portal_confirmation_sign', string='Online Signature', readonly=False)
portal_confirmation_pay = fields.Boolean(related='company_id.portal_confirmation_pay', string='Online Payment', readonly=False)
group_sale_delivery_address = fields.Boolean("Customer Addresses", implied_group='sale.group_delivery_invoice_address')
group_proforma_sales = fields.Boolean(string="Pro-Forma Invoice", implied_group='sale.group_proforma_sales',
help="Allows you to send pro-forma invoice.")
default_invoice_policy = fields.Selection([
@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_invoice_document_inherit_sale" inherit_id="account.report_invoice_document">
<xpath expr="//address" position="attributes">
<attribute name="groups">!sale.group_delivery_invoice_address</attribute>
</xpath>
<xpath expr="//address" position="before">
<t t-if="o.partner_shipping_id and (o.partner_shipping_id != o.partner_id)">
<t t-set="information_block">
<div groups="sale.group_delivery_invoice_address" name="shipping_address_block">
<strong>Shipping Address:</strong>
<div t-field="o.partner_shipping_id"
t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}'/>
</div>
</t>
</t>
<div t-field="o.partner_id"
t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}' groups="sale.group_delivery_invoice_address"/>
</xpath>
</template>
</odoo>
-5
View File
@@ -6,11 +6,6 @@
<field name="category_id" ref="base.module_category_hidden"/>
</record>
<record id="group_delivery_invoice_address" model="res.groups">
<field name="name">Addresses in Sales Orders</field>
<field name="category_id" ref="base.module_category_hidden"/>
</record>
<record id="group_warning_sale" model="res.groups">
<field name="name">A warning can be set on a product or a customer (Sale)</field>
<field name="category_id" ref="base.module_category_hidden"/>
@@ -214,18 +214,6 @@
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box" id="invoice_delivery_addresses">
<div class="o_setting_left_pane">
<field name="group_sale_delivery_address"/>
</div>
<div class="o_setting_right_pane">
<label for="group_sale_delivery_address"/>
<a href="https://www.odoo.com/documentation/15.0/applications/sales/sales/send_quotations/different_addresses.html" title="Documentation" class="o_doc_link" target="_blank"></a>
<div class="text-muted">
Select specific invoice and delivery addresses
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box" id="quotation_validity_days">
<div class="o_setting_left_pane">
<field name="use_quotation_validity_days"/>
+2 -7
View File
@@ -318,8 +318,8 @@
<group name="sale_header">
<group name="partner_details">
<field name="partner_id" widget="res_partner_many2one" context="{'res_partner_search_mode': 'customer', 'show_address': 1, 'show_vat': True}" options='{"always_reload": True}'/>
<field name="partner_invoice_id" groups="sale.group_delivery_invoice_address" context="{'default_type':'invoice'}" options='{"always_reload": True}'/>
<field name="partner_shipping_id" groups="sale.group_delivery_invoice_address" context="{'default_type':'delivery'}" options='{"always_reload": True}'/>
<field name="partner_invoice_id" groups="account.group_delivery_invoice_address" context="{'default_type':'invoice'}" options='{"always_reload": True}'/>
<field name="partner_shipping_id" groups="account.group_delivery_invoice_address" context="{'default_type':'delivery'}" options='{"always_reload": True}'/>
</group>
<group name="order_details">
<field name="validity_date" attrs="{'invisible': [('state', 'in', ['sale', 'done'])]}"/>
@@ -1223,11 +1223,6 @@
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='partner_id']" position="after">
<field name="partner_shipping_id"
groups="sale.group_delivery_invoice_address"
attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund', 'out_receipt'))]}"/>
</xpath>
<xpath expr="//field[@name='invoice_line_ids']//field[@name='discount']" position="attributes">
<attribute name="groups">product.group_discount_per_so_line</attribute>
</xpath>
+2 -2
View File
@@ -7,10 +7,10 @@
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="//group/group/span/field[@name='type']" position="attributes">
<attribute name="groups">sale.group_delivery_invoice_address</attribute>
<attribute name="groups">account.group_delivery_invoice_address</attribute>
</xpath>
<xpath expr="//field[@name='child_ids']//field[@name='type']" position="attributes">
<attribute name="groups">sale.group_delivery_invoice_address</attribute>
<attribute name="groups">account.group_delivery_invoice_address</attribute>
</xpath>
</field>
</record>
@@ -36,7 +36,7 @@ class TestUi(odoo.tests.HttpCase, TestProductConfiguratorCommon):
'groups_id': [
(4, self.env.ref('product.group_product_variant').id),
(4, self.env.ref('product.group_product_pricelist').id),
(4, self.env.ref('sale.group_delivery_invoice_address').id),
(4, self.env.ref('account.group_delivery_invoice_address').id),
],
})
@@ -17,7 +17,7 @@ class ResConfigSettings(models.TransientModel):
('website', "Delivery methods are selectable on the website: the customer pays for shipping costs"),
], string="Shipping Management")
group_delivery_invoice_address = fields.Boolean(string="Shipping Address", implied_group='sale.group_delivery_invoice_address', group='base.group_portal,base.group_user,base.group_public')
group_delivery_invoice_address = fields.Boolean(string="Shipping Address", implied_group='account.group_delivery_invoice_address', group='base.group_portal,base.group_user,base.group_public')
group_show_uom_price = fields.Boolean(default=False, string="Base Unit Price", implied_group="website_sale.group_show_uom_price", group='base.group_portal,base.group_user,base.group_public')
module_website_sale_digital = fields.Boolean("Digital Content")
@@ -22,15 +22,15 @@
</record>
<record id="base.group_user" model="res.groups">
<field name="implied_ids" eval="[(4, ref('sale.group_delivery_invoice_address'))]"/>
<field name="implied_ids" eval="[(4, ref('account.group_delivery_invoice_address'))]"/>
</record>
<record id="base.group_public" model="res.groups">
<field name="implied_ids" eval="[(4, ref('sale.group_delivery_invoice_address'))]"/>
<field name="implied_ids" eval="[(4, ref('account.group_delivery_invoice_address'))]"/>
</record>
<record id="base.group_portal" model="res.groups">
<field name="implied_ids" eval="[(4, ref('sale.group_delivery_invoice_address'))]"/>
<field name="implied_ids" eval="[(4, ref('account.group_delivery_invoice_address'))]"/>
</record>
<!--
+4 -4
View File
@@ -1308,7 +1308,7 @@
</t>
</div>
</div>
<t t-if="not only_services" groups="sale.group_delivery_invoice_address">
<t t-if="not only_services" groups="account.group_delivery_invoice_address">
<div class="row">
<div class="col-lg-12">
<h3 class="o_page_header mt16 mb4">Shipping Address</h3>
@@ -1423,7 +1423,7 @@
<t t-if="partner_id == website_sale_order.partner_shipping_id.id == website_sale_order.partner_invoice_id.id">
<div class="alert alert-warning" role="alert" t-if="not only_services">
<h4 class="alert-heading">Be aware!</h4>
<p groups="sale.group_delivery_invoice_address">
<p groups="account.group_delivery_invoice_address">
You are editing your <b>billing and shipping</b> addresses at the same time!<br/>
If you want to modify your shipping address, create a <a href='/shop/address'>new address</a>.
</p>
@@ -1567,7 +1567,7 @@
<b>Billing<t t-if="same_shipping and not only_services"> &amp; Shipping</t>: </b>
<span t-esc="order.partner_id" t-options="dict(widget='contact', fields=['address'], no_marker=True, separator=', ')" class="address-inline"/>
</div>
<div t-if="not same_shipping and not only_services" groups="sale.group_delivery_invoice_address">
<div t-if="not same_shipping and not only_services" groups="account.group_delivery_invoice_address">
<b>Shipping: </b>
<span t-esc="order.partner_shipping_id" t-options="dict(widget='contact', fields=['address'], no_marker=True, separator=', ')" class="address-inline"/>
</div>
@@ -1797,7 +1797,7 @@
<div class="card-body">
<t t-set="same_shipping" t-value="bool(order.partner_shipping_id==order.partner_id or only_services)" />
<div><b>Billing <t t-if="same_shipping and not only_services"> &amp; Shipping</t>: </b><span t-esc='order.partner_id' t-options="dict(widget='contact', fields=['address'], no_marker=True, separator=', ')" class="address-inline"/></div>
<div t-if="not same_shipping and not only_services" groups="sale.group_delivery_invoice_address"><b>Shipping: </b><span t-esc='order.partner_shipping_id' t-options="dict(widget='contact', fields=['address'], no_marker=True, separator=', ')" class="address-inline"/></div>
<div t-if="not same_shipping and not only_services" groups="account.group_delivery_invoice_address"><b>Shipping: </b><span t-esc='order.partner_shipping_id' t-options="dict(widget='contact', fields=['address'], no_marker=True, separator=', ')" class="address-inline"/></div>
</div>
</div>
<div class="oe_structure mt-3" id="oe_structure_website_sale_confirmation_2"/>