[IMP] sale: Apply misc styling improvements + remove dead context keys

This commit is contained in:
Yannick Tivisse
2021-12-02 12:12:03 +01:00
parent 280cf015e1
commit 3c07a3fecd
15 changed files with 37 additions and 48 deletions
+2 -2
View File
@@ -34,9 +34,9 @@ class AccountMove(models.Model):
"""
Trigger the change of fiscal position when the shipping address is modified.
"""
delivery_partner_id = self.env['res.partner'].browse(self._get_invoice_delivery_partner_id())
delivery_partner = self.env['res.partner'].browse(self._get_invoice_delivery_partner_id())
fiscal_position = self.env['account.fiscal.position'].with_company(self.company_id)._get_fiscal_position(
self.partner_id, delivery=delivery_partner_id)
self.partner_id, delivery=delivery_partner)
if fiscal_position:
self.fiscal_position_id = fiscal_position
+1 -1
View File
@@ -53,7 +53,7 @@ class ProductTemplate(models.Model):
@api.depends('sale_ok')
def _compute_expense_policy(self):
self.filtered(lambda t: not t.sale_ok).update({'expense_policy': 'no'})
self.filtered(lambda t: not t.sale_ok).expense_policy = 'no'
@api.depends('product_variant_ids.sales_count')
def _compute_sales_count(self):
+9 -10
View File
@@ -175,25 +175,24 @@ class SaleOrder(models.Model):
required=True, change_default=True, index=True, tracking=1,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",)
partner_invoice_id = fields.Many2one(
'res.partner', string='Invoice Address',
readonly=False, required=True, pre_compute=True,
'res.partner', string='Invoice Address', required=True,
compute='_compute_partner_invoice_id', store=True, readonly=False, pre_compute=True,
states={'done': [('readonly', True)], 'cancel': [('readonly', True)]},
compute='_compute_partner_invoice_id', store=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",)
partner_shipping_id = fields.Many2one(
'res.partner', string='Delivery Address', readonly=False, required=True,
'res.partner', string='Delivery Address', required=True,
compute='_compute_partner_shipping_id', store=True, readonly=False, pre_compute=True,
states={'done': [('readonly', True)], 'cancel': [('readonly', True)]},
compute='_compute_partner_shipping_id', store=True, pre_compute=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",)
pricelist_id = fields.Many2one(
'product.pricelist', string='Pricelist', check_company=True, # Unrequired company
required=False, readonly=False, store=True,
compute='_compute_pricelist_id', pre_compute=True,
'product.pricelist', string='Pricelist', required=False, check_company=True, # Unrequired company
compute='_compute_pricelist_id', store=True, pre_compute=True, readonly=False,
states={'sale': [('readonly', True)], 'done': [('readonly', True)], 'cancel': [('readonly', True)]},
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", tracking=1,
help="If you change the pricelist, only newly added lines will be affected.")
currency_id = fields.Many2one(related='pricelist_id.currency_id', depends=["pricelist_id"], store=True, ondelete="restrict")
currency_id = fields.Many2one(
related='pricelist_id.currency_id', depends=["pricelist_id"], store=True, pre_compute=True, ondelete="restrict")
analytic_account_id = fields.Many2one(
'account.analytic.account', 'Analytic Account',
readonly=True, copy=False, check_company=True, # Unrequired company
@@ -536,7 +535,7 @@ class SaleOrder(models.Model):
vals['name'] = self.env['ir.sequence'].next_by_code(
'sale.order', sequence_date=seq_date) or _('New')
return super(SaleOrder, self).create(vals_list)
return super().create(vals_list)
def _compute_field_value(self, field):
if field.name == 'invoice_status' and not self.env.context.get('mail_activity_automation_skip'):
+2 -10
View File
@@ -418,7 +418,7 @@ class SaleOrderLine(models.Model):
# remove packaging if not match the product
if line.product_packaging_id.product_id != line.product_id:
line.product_packaging_id = False
# suggest biggest suitable packaging
# Find biggest suitable packaging
if line.product_id and line.product_uom_qty and line.product_uom:
line.product_packaging_id = line.product_id.packaging_ids.filtered(
'sales')._find_suitable_product_packaging(line.product_uom_qty, line.product_uom)
@@ -629,13 +629,7 @@ class SaleOrderLine(models.Model):
for line in self:
if not line.product_id:
continue
product = line.product_id.with_context(
lang=get_lang(line.env, line.order_id.partner_id.lang).code,
partner=line.order_id.partner_id,
quantity=line.product_uom_qty,
date=line.order_id.date_order,
pricelist=line.order_id.pricelist_id.id,
uom=line.product_uom.id)
product = line.product_id.with_context(lang=line.order_partner_id.lang)
line.name = line.get_sale_order_line_multiline_description_sale(product)
@api.depends('product_id')
@@ -684,7 +678,6 @@ class SaleOrderLine(models.Model):
continue
if line.order_id.pricelist_id and line.order_partner_id:
product = line.product_id.with_context(
lang=line.order_id.partner_id.lang,
partner=line.order_partner_id,
quantity=line.product_uom_qty,
date=line.order_id.date_order,
@@ -796,7 +789,6 @@ class SaleOrderLine(models.Model):
line.discount = 0.0
product = line.product_id.with_context(
lang=line.order_id.partner_id.lang,
partner=line.order_partner_id,
quantity=line.product_uom_qty,
date=line.order_id.date_order,
+7 -7
View File
@@ -1,16 +1,16 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_sale_product_attribute_value_config
from . import test_sale_to_invoice
from . import test_sale_order
from . import test_sale_pricelist
from . import test_access_rights
from . import test_accrued_sale_orders
from . import test_onchange
from . import test_payment_flow
from . import test_reinvoice
from . import test_access_rights
from . import test_sale_flow
from . import test_sale_order
from . import test_sale_pricelist
from . import test_sale_product_attribute_value_config
from . import test_sale_refund
from . import test_sale_signature
from . import test_sale_flow
from . import test_accrued_sale_orders
from . import test_sale_tax_totals
from . import test_sale_to_invoice
+2 -2
View File
@@ -122,7 +122,7 @@ class TestSaleOrder(TestSaleCommon):
order = self.env['sale.order'].create({
'partner_id': self.partner_a.id,
})
order_lines = self.env['sale.order.line'].create([
self.env['sale.order.line'].create([
{
'display_type': 'line_section',
'name': 'Dummy section',
@@ -800,7 +800,7 @@ class TestSaleOrder(TestSaleCommon):
product = product_tmpl.product_variant_id
fpos = self.env['account.fiscal.position'].create(dict(name="fiscal position", sequence=1))
fp_tax_id = self.env['account.fiscal.position.tax'].create({
self.env['account.fiscal.position.tax'].create({
'position_id': fpos.id,
'tax_src_id': tax_include.id,
'tax_dest_id': tax_exclude.id,
-1
View File
@@ -501,7 +501,6 @@ class SaleOrderLine(models.Model):
related_program_lines |= line.order_id.order_line.filtered(lambda l: l.product_id.id == related_program.discount_line_product_id.id) - line
return super(SaleOrderLine, self | related_program_lines).unlink()
@api.depends('product_id')
def _compute_tax_id(self):
reward_lines = self.filtered('is_reward_line')
super(SaleOrderLine, self - reward_lines)._compute_tax_id()
@@ -6,7 +6,7 @@ from odoo.exceptions import UserError
from odoo.tests import tagged
@tagged('post_install', '-at_install', 'program_numbers')
@tagged('post_install', '-at_install')
class TestSaleCouponProgramNumbers(TestSaleCouponCommon):
def setUp(self):
+2 -2
View File
@@ -52,8 +52,8 @@ class SaleOrder(models.Model):
@api.depends('partner_id', 'sale_order_template_id')
def _compute_note(self):
super(SaleOrder, self)._compute_note()
for order in self:
super()._compute_note()
for order in self.filtered('sale_order_template_id'):
template = order.sale_order_template_id.with_context(lang=order.partner_id.lang)
order.note = template.note if not is_html_empty(template.note) else order.note
@@ -45,7 +45,6 @@ class SaleOrder(models.Model):
if self.grid and self.grid_update:
grid = json.loads(self.grid)
product_template = self.env['product.template'].browse(grid['product_template_id'])
product_ids = set()
dirty_cells = grid['changes']
Attrib = self.env['product.template.attribute.value']
default_so_line_vals = {}
@@ -69,8 +68,6 @@ class SaleOrder(models.Model):
if not diff:
continue
product_ids.add(product.id)
# TODO keep qty check? cannot be 0 because we only get cell changes ...
if order_lines:
if qty == 0:
@@ -115,7 +112,7 @@ class SaleOrder(models.Model):
product_uom_qty=qty,
product_no_variant_attribute_value_ids=no_variant_attribute_values.ids)
))
if product_ids and new_lines:
if new_lines:
# Add new SO lines
self.update(dict(order_line=new_lines))
@@ -46,11 +46,11 @@ class SaleOrderLine(models.Model):
@api.model_create_multi
def create(self, vals_list):
vals_list = [self._inject_quotation_description(vals) for vals in vals_list]
return super(SaleOrderLine, self).create(vals_list)
return super().create(vals_list)
def write(self, values):
values = self._inject_quotation_description(values)
return super(SaleOrderLine, self).write(values)
return super().write(values)
def _inject_quotation_description(self, values):
values = dict(values or {})
@@ -34,7 +34,7 @@ class SaleOrderTemplateLine(models.Model):
@api.model_create_multi
def create(self, vals_list):
vals_list = [self._inject_quotation_description(vals) for vals in vals_list]
return super(SaleOrderTemplateLine, self).create(vals_list)
return super().create(vals_list)
def write(self, values):
values = self._inject_quotation_description(values)
@@ -5,7 +5,7 @@ from odoo.fields import Command
from odoo.tests import tagged
from odoo.tests.common import Form
@tagged('post_install', '-at_install', 'project_billing')
@tagged('post_install', '-at_install')
class TestProjectBilling(TestCommonSaleTimesheet):
""" This test suite provide checks for miscellaneous small things. """
+1 -1
View File
@@ -834,7 +834,7 @@ class WebsiteSale(http.Controller):
else:
partner_id = self._checkout_form_save(mode, post, kw)
if mode[1] == 'billing':
order.with_context(not_self_saleperson=True).partner_id = partner_id
order.partner_id = partner_id
# This is the *only* thing that the front end user will see/edit anyway when choosing billing address
order.partner_invoice_id = partner_id
if not kw.get('use_same'):
+5 -3
View File
@@ -328,9 +328,11 @@ class Website(models.Model):
fiscal_position = sale_order.fiscal_position_id.id
# change the partner, and trigger the onchange
sale_order.with_context(not_self_saleperson=True).write({'partner_id': partner.id})
sale_order.write({'partner_invoice_id': partner.id})
sale_order['payment_term_id'] = self.sale_get_payment_term(partner)
sale_order.write({
'partner_id': partner.id,
'partner_invoice_id': partner.id,
'payment_term_id': self.sale_get_payment_term(partner),
})
# check the pricelist : update it if the pricelist is not the 'forced' one
values = {}