11# Copyright 2018 ACSONE SA/NV
22# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33
4- from odoo import SUPERUSER_ID , _ , api , fields , models
4+ from odoo import api , fields , models
55from odoo .exceptions import UserError
66from odoo .tools import float_is_zero
77from odoo .tools .misc import format_date
@@ -62,13 +62,6 @@ def _compute_amount_all(self):
6262 required = True ,
6363 )
6464 currency_id = fields .Many2one ("res.currency" , related = "pricelist_id.currency_id" )
65- analytic_account_id = fields .Many2one (
66- comodel_name = "account.analytic.account" ,
67- string = "Analytic Account" ,
68- copy = False ,
69- check_company = True ,
70- domain = "['|', ('company_id', '=', False), ('company_id', '=', company_id)]" ,
71- )
7265 payment_term_id = fields .Many2one (
7366 "account.payment.term" ,
7467 string = "Payment Terms" ,
@@ -110,7 +103,8 @@ def _compute_amount_all(self):
110103 sale_count = fields .Integer (compute = "_compute_sale_count" )
111104
112105 fiscal_position_id = fields .Many2one (
113- "account.fiscal.position" , string = "Fiscal Position"
106+ "account.fiscal.position" ,
107+ check_company = True ,
114108 )
115109
116110 amount_untaxed = fields .Monetary (
@@ -236,15 +230,15 @@ def onchange_partner_id(self):
236230
237231 if self .partner_id .user_id :
238232 values ["user_id" ] = self .partner_id .user_id .id
239- if self .partner_id .team_id :
240- values ["team_id" ] = self .partner_id .team_id .id
233+ if self .partner_id .user_id . sale_team_id :
234+ values ["team_id" ] = self .partner_id .user_id . sale_team_id .id
241235 self .update (values )
242236
243237 def unlink (self ):
244238 for order in self :
245239 if order .state not in ("draft" , "expired" ) or order ._check_active_orders ():
246240 raise UserError (
247- _ (
241+ self . env . _ (
248242 "You can not delete an open blanket or "
249243 "with active sale orders! "
250244 "Try to cancel it before."
@@ -256,12 +250,12 @@ def _validate(self):
256250 try :
257251 today = fields .Date .today ()
258252 for order in self :
259- assert order .validity_date , _ ("Validity date is mandatory" )
260- assert order .validity_date > today , _ (
253+ assert order .validity_date , self . env . _ ("Validity date is mandatory" )
254+ assert order .validity_date > today , self . env . _ (
261255 "Validity date must be in the future"
262256 )
263- assert order .partner_id , _ ("Partner is mandatory" )
264- assert len (order .line_ids ) > 0 , _ ("Must have some lines" )
257+ assert order .partner_id , self . env . _ ("Partner is mandatory" )
258+ assert len (order .line_ids ) > 0 , self . env . _ ("Must have some lines" )
265259 order .line_ids ._validate ()
266260 except AssertionError as e :
267261 raise UserError (e ) from e
@@ -292,7 +286,7 @@ def action_cancel(self):
292286 for order in self :
293287 if order ._check_active_orders ():
294288 raise UserError (
295- _ (
289+ self . env . _ (
296290 "You can not delete a blanket order with opened "
297291 "sale orders! "
298292 "Try to cancel them before."
@@ -419,9 +413,9 @@ def _compute_amount(self):
419413 product_uom = fields .Many2one ("uom.uom" , string = "Unit of Measure" )
420414 price_unit = fields .Float (string = "Price" , digits = "Product Price" )
421415 taxes_id = fields .Many2many (
422- "account.tax" ,
423- string = "Taxes" ,
424- domain = [ "|" , ( "active" , "=" , False ), ( "active" , "=" , True )] ,
416+ comodel_name = "account.tax" ,
417+ context = { "active_test" : False } ,
418+ check_company = True ,
425419 )
426420 date_schedule = fields .Date (string = "Scheduled Date" )
427421 original_uom_qty = fields .Float (
@@ -483,12 +477,14 @@ def _compute_amount(self):
483477 def _compute_display_name (self ):
484478 if self .env .context .get ("from_sale_order" ):
485479 for record in self :
486- name = "[%s]" % record .order_id .name
480+ name = f"[ { record .order_id .name } ]"
487481 if record .date_schedule :
488482 formatted_date = format_date (record .env , record .date_schedule )
489- name += " - {}: {}" .format (_ ("Date Scheduled" ), formatted_date )
483+ name += " - {}: {}" .format (
484+ self .env ._ ("Date Scheduled" ), formatted_date
485+ )
490486 name += " ({}: {} {})" .format (
491- _ ("remaining" ),
487+ self . env . _ ("remaining" ),
492488 record .remaining_uom_qty ,
493489 record .product_uom .name ,
494490 )
@@ -511,12 +507,11 @@ def _get_real_price_currency(self, product, rule_id, qty, uom, pricelist_id):
511507 product_currency = None
512508 if rule_id :
513509 pricelist_item = PricelistItem .browse (rule_id )
514- if pricelist_item .pricelist_id . discount_policy == "without_discount" :
510+ if pricelist_item ._show_discount () :
515511 while (
516512 pricelist_item .base == "pricelist"
517513 and pricelist_item .base_pricelist_id
518- and pricelist_item .base_pricelist_id .discount_policy
519- == "without_discount"
514+ and pricelist_item ._show_discount ()
520515 ):
521516 price , rule_id = pricelist_item .base_pricelist_id .with_context (
522517 uom = uom .id
@@ -571,9 +566,6 @@ def _get_display_price(self):
571566 currency = self .currency_id ,
572567 )
573568
574- if self .order_id .pricelist_id .discount_policy == "with_discount" :
575- return pricelist_price
576-
577569 if not self .pricelist_item_id :
578570 # No pricelist rule found => no discount from pricelist
579571 return pricelist_price
@@ -590,7 +582,7 @@ def _get_pricelist_price_before_discount(self):
590582
591583 return self .pricelist_item_id ._compute_price_before_discount (
592584 product = self .product_id ,
593- quantity = self .product_uom_qty or 1.0 ,
585+ quantity = self .original_uom_qty or 1.0 ,
594586 uom = self .product_uom ,
595587 date = fields .Date .today (),
596588 currency = self .currency_id ,
@@ -616,15 +608,9 @@ def onchange_product(self):
616608 self .name = name
617609
618610 fpos = self .order_id .fiscal_position_id
619- if self .env .uid == SUPERUSER_ID :
620- company_id = self .env .company .id
621- self .taxes_id = fpos .map_tax (
622- self .product_id .taxes_id .filtered (
623- lambda r : r .company_id .id == company_id
624- )
625- )
626- else :
627- self .taxes_id = fpos .map_tax (self .product_id .taxes_id )
611+ self .taxes_id = fpos .map_tax (
612+ self .product_id .taxes_id ._filter_taxes_by_company (self .company_id )
613+ )
628614
629615 @api .depends (
630616 "sale_lines.order_id.state" ,
@@ -682,10 +668,10 @@ def _validate(self):
682668 for line in self :
683669 assert (
684670 not line .display_type and line .price_unit > 0.0
685- ) or line .display_type , _ ("Price must be greater than zero" )
671+ ) or line .display_type , self . env . _ ("Price must be greater than zero" )
686672 assert (
687673 not line .display_type and line .original_uom_qty > 0.0
688- ) or line .display_type , _ ("Quantity must be greater than zero" )
674+ ) or line .display_type , self . env . _ ("Quantity must be greater than zero" )
689675 except AssertionError as e :
690676 raise UserError (e ) from e
691677
@@ -729,7 +715,7 @@ def write(self, values):
729715 lambda line : line .display_type != values .get ("display_type" )
730716 ):
731717 raise UserError (
732- _ (
718+ self . env . _ (
733719 """
734720 You cannot change the type of a sale order line.
735721 Instead you should delete the current line and create a new line
0 commit comments