Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX+IMP] sale_order_type: New computed writable + migration fixes
* Switch onchange on the main field to computed writable fields * Record rule is not up to v13 * Added migration script for record rule * Proper payment term field name in invoice * Realign tests
- Loading branch information
1 parent
4a69446
commit 8e40947
Showing
9 changed files
with
87 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<odoo> | ||
<record id="sale_order_type_comp_rule" model="ir.rule"> | ||
<field | ||
name="domain_force" | ||
>['|',('company_id','=',False),('company_id','in',company_ids)]</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright 2020 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openupgradelib import openupgrade # pylint: disable=W7936 | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.load_data( | ||
env.cr, "sale_order_type", "migrations/13.0.1.0.0/noupdate_changes.xml" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
# Copyright 2020 Tecnativa - Pedro M. Baeza | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
def _get_order_type(self): | ||
return self.env["sale.order.type"].search([], limit=1) | ||
|
||
sale_type_id = fields.Many2one( | ||
comodel_name="sale.order.type", string="Sale Type", default=_get_order_type | ||
comodel_name="sale.order.type", | ||
string="Sale Type", | ||
compute="_compute_sale_type_id", | ||
readonly=False, | ||
store=True, | ||
) | ||
|
||
@api.onchange("partner_id", "company_id") | ||
def _onchange_partner_id(self): | ||
res = super(AccountMove, self)._onchange_partner_id() | ||
sale_type = ( | ||
self.partner_id.sale_type or self.partner_id.commercial_partner_id.sale_type | ||
) | ||
if sale_type: | ||
self.sale_type_id = sale_type | ||
return res | ||
@api.depends("partner_id", "company_id") | ||
def _compute_sale_type_id(self): | ||
for record in self: | ||
if not record.partner_id: | ||
record.sale_type_id = self.env["sale.order.type"].search([], limit=1) | ||
else: | ||
sale_type = ( | ||
record.partner_id.with_context( | ||
force_company=record.company_id.id | ||
).sale_type | ||
or self.partner_id.commercial_partner_id.with_context( | ||
force_company=record.company_id.id | ||
).sale_type | ||
) | ||
if sale_type: | ||
record.sale_type_id = sale_type | ||
|
||
@api.onchange("sale_type_id") | ||
def onchange_sale_type_id(self): | ||
# TODO: To be changed to computed stored readonly=False if possible in v14? | ||
if self.sale_type_id.payment_term_id: | ||
self.payment_term = self.sale_type_id.payment_term_id.id | ||
self.invoice_payment_term_id = self.sale_type_id.payment_term_id.id | ||
if self.sale_type_id.journal_id: | ||
self.journal_id = self.sale_type_id.journal_id.id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters