3
3
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
4
4
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
5
5
6
- from odoo import api , fields , models , _
6
+ from odoo import _ , api , fields , models
7
7
8
8
9
9
class SaleOrder (models .Model ):
@@ -84,41 +84,49 @@ def _prepare_delivery_line_vals(self, carrier, price_unit):
84
84
context = {}
85
85
if self .partner_id :
86
86
# set delivery detail in the customer language
87
- context [' lang' ] = self .partner_id .lang
87
+ context [" lang" ] = self .partner_id .lang
88
88
carrier = carrier .with_context (lang = self .partner_id .lang )
89
89
90
90
# Apply fiscal position
91
- taxes = carrier .product_id .taxes_id .filtered (lambda t : t .company_id .id == self .company_id .id )
91
+ taxes = carrier .product_id .taxes_id .filtered (
92
+ lambda t : t .company_id .id == self .company_id .id
93
+ )
92
94
taxes_ids = taxes .ids
93
95
if self .partner_id and self .fiscal_position_id :
94
96
taxes_ids = self .fiscal_position_id .map_tax (taxes ).ids
95
97
96
98
# Create the sales order line
97
99
98
100
if carrier .product_id .description_sale :
99
- so_description = '%s: %s' % (carrier .name , carrier .product_id .description_sale )
101
+ so_description = "%s: %s" % (
102
+ carrier .name ,
103
+ carrier .product_id .description_sale ,
104
+ )
100
105
else :
101
106
so_description = carrier .name
102
107
values = {
103
- ' order_id' : self .id ,
104
- ' name' : so_description ,
105
- ' product_uom_qty' : 1 ,
106
- ' product_uom' : carrier .product_id .uom_id .id ,
107
- ' product_id' : carrier .product_id .id ,
108
- ' tax_id' : [(6 , 0 , taxes_ids )],
109
- ' is_delivery' : True ,
108
+ " order_id" : self .id ,
109
+ " name" : so_description ,
110
+ " product_uom_qty" : 1 ,
111
+ " product_uom" : carrier .product_id .uom_id .id ,
112
+ " product_id" : carrier .product_id .id ,
113
+ " tax_id" : [(6 , 0 , taxes_ids )],
114
+ " is_delivery" : True ,
110
115
}
111
- if carrier .invoice_policy == 'real' :
112
- values ['price_unit' ] = 0
113
- values ['name' ] += _ (' (Estimated Cost: %s )' , self ._format_currency_amount (price_unit ))
116
+ if carrier .invoice_policy == "real" :
117
+ values ["price_unit" ] = 0
118
+ values ["name" ] += _ (
119
+ " (Estimated Cost: %s )" , self ._format_currency_amount (price_unit )
120
+ )
114
121
else :
115
- values [' price_unit' ] = price_unit
116
- if carrier .free_over and self .currency_id .is_zero (price_unit ) :
117
- values [' name' ] += ' \n ' + _ (' Free Shipping' )
122
+ values [" price_unit" ] = price_unit
123
+ if carrier .free_over and self .currency_id .is_zero (price_unit ):
124
+ values [" name" ] += " \n " + _ (" Free Shipping" )
118
125
if self .order_line :
119
- values [' sequence' ] = self .order_line [- 1 ].sequence + 1
126
+ values [" sequence" ] = self .order_line [- 1 ].sequence + 1
120
127
del context
121
128
return values
129
+
122
130
# end of the odoo part
123
131
124
132
def _update_delivery_line (self , delivery_line , price_unit ):
@@ -131,13 +139,13 @@ def _update_delivery_line(self, delivery_line, price_unit):
131
139
# Tax is set with a SET command
132
140
clear = update = False
133
141
for cmd in val :
134
- if cmd [0 ] == fields . Command . SET :
142
+ if cmd [0 ] == 6 :
135
143
if delivery_line [f ].ids != cmd [2 ]:
136
144
update = True
137
145
else :
138
146
clear = True
139
147
if clear :
140
- new_vals [f ] = [fields . Command . CLEAR ] + val
148
+ new_vals [f ] = [( 5 , 0 , 0 ) ] + val
141
149
elif update :
142
150
new_vals [f ] = val
143
151
elif isinstance (field_def , fields .Many2one ):
0 commit comments