Merge lp:~bellini666/stoqlib/freight into lp:~stoq-dev/stoqlib/master

Proposed by Thiago Bellini
Status: Merged
Merged at revision: 3312
Proposed branch: lp:~bellini666/stoqlib/freight
Merge into: lp:~stoq-dev/stoqlib/master
Diff against target: 687 lines (+238/-169)
5 files modified
data/glade/ReceivingInvoiceSlave.glade (+28/-71)
data/glade/StartPurchaseStep.glade (+78/-60)
data/sql/patch-02-22.sql (+7/-0)
stoqlib/domain/receiving.py (+42/-2)
stoqlib/gui/slaves/receivingslave.py (+83/-36)
To merge this branch: bzr merge lp:~bellini666/stoqlib/freight
Reviewer Review Type Date Requested Status
Ronaldo Maia Approve
Thiago Bellini Needs Resubmitting
Review via email: mp+49112@code.launchpad.net

Description of the change

Freight type on ReceivingOrder.

To post a comment you must log in.
Revision history for this message
Ronaldo Maia (romaia) wrote :
Download full text (9.1 KiB)

> === added file 'data/sql/patch-02-20.sql'

Esse nome do patch vai conflitar, pois já adicionei mais patches depois desse.

> === renamed file 'data/sql/patch-02-20.sql' => 'data/sql/patch-02-20.sql.moved'

Esse é um deles, por exemplo

> === modified file 'stoqlib/domain/receiving.py'
> @@ -129,10 +130,25 @@

> +    freight_types = {FREIGHT_FOB_PAYMENT: _("FOB - Freight value "
> +                                            "on a new payment"),
> +                     FREIGHT_FOB_INSTALLMENTS: _("FOB - Freight value "
> +                                                 "on installments"),
> +                     FREIGHT_CIF_UNKNOWN: _("CIF - Freight value "
> +                                            "is unknown"),
> +                     FREIGHT_CIF_INVOICE: _("CIF - Freight value "
> +                                            "highlighted on invoice")}

Crie essas descrições como unicode: u"..."

> @@ -210,7 +226,7 @@
>         description = _(u'Freight for purchase %s' %
> -                                self.purchase.get_order_number_str())
> +                        self.purchase.get_order_number_str())

Eu prefiro que essas mudanças que não tem muito a ver com o patch sejam evitadas. (a não ser que vc realmente já esteja editando as redondezas próximas)

Elas só deixam o patch maior e mais complicado de revisar.

> @@ -252,6 +268,28 @@
>
> +    def get_freight_types(self):
> +        """Returns a list with available freight types"""
> +        return [f for f in (self.FREIGHT_FOB_PAYMENT,
> +                            self.FREIGHT_FOB_INSTALLMENTS,
> +                            self.FREIGHT_CIF_UNKNOWN,
> +                            self.FREIGHT_CIF_INVOICE)]

Vc não precisar desse método (vou explicar no lugar onde vc usou ele). Mas apenas comentando já que ele está aqui:

1) ele poderia ser um classmethod. Dessa forma vc poderia usar ele mesmo sem uma instancia.

2) Vc poderia fazer simplesmente:

        return (self.FREIGHT_FOB_PAYMENT,
                self.FREIGHT_FOB_INSTALLMENTS,
                self.FREIGHT_CIF_UNKNOWN,
                self.FREIGHT_CIF_INVOICE)

Notou a diferença? vc criou uma tupla (um iterable), iterou sobre ele, criando uma lista (um outro iterable). Bastaria ter retornado essa primeira tupla.

3) Apenas para ilustrar, uma outra forma de fazer isso (há casos em que isso é muito mais apropriado que esse):

def foo():
   for f in (self.FREIGHT, ...):
      yield f

Como dever de casa, fica ver o que o yield faz.

> +    def get_freight_type_adapted_from_payment(self):
> +        """Returns a freight_type based on the purchase's freight_type"""

Esse método pode ser privado. Não gostei muito do nome também. Não está muito condizente com a descrição dele.

_get_freight_type_from_purchase parece melhor. O que acha? ou mesmo _guess_freight_type

> @@ -300,7 +338,11 @@
>
>         if self.ipi_total:
>             total_surcharge += self.ipi_total
> -        if self.freight_total:
> +
> +        # CIF freights doesn't generate payments.

# CIF freights *don't* ... (plural)

> +        if (self.freight_total and
> +            self.freight_type != self.FREIGHT_CIF_UNKNOWN and
> +            self.freight...

Read more...

review: Approve
Revision history for this message
Thiago Bellini (bellini666) wrote :
Download full text (7.7 KiB)

Ronaldo,

De certo modo preciso pedir desculpa pela "falta de atenção" no
código. Alguns detalhes
ainda tem um desconto pela minha ainda pouca experiência com Python, mas algumas
coisas que você destacou foram bem porquice minha! Vou começar a prestar mais
atenção nesses detalhes...bem mais...
E mal também pelas várias mudanças de posição, acerto der pep8 e coisas do tipo,
não sabia que isso atrapalhava tanto no patch (se bem que era meio obvio).
Enfim, vou corrigir agora os pontos que você destacou. Vou acabar
fazendo um ou outro
comentário nos seus comentários.

2011/2/9 Ronaldo Maia <email address hidden>:
> Review: Approve
>> === added file 'data/sql/patch-02-20.sql'
>
> Esse nome do patch vai conflitar, pois já adicionei mais patches depois desse.
>
>
>> === renamed file 'data/sql/patch-02-20.sql' => 'data/sql/patch-02-20.sql.moved'
>
> Esse é um deles, por exemplo
>
>> === modified file 'stoqlib/domain/receiving.py'
>> @@ -129,10 +130,25 @@
>
>> +    freight_types = {FREIGHT_FOB_PAYMENT: _("FOB - Freight value "
>> +                                            "on a new payment"),
>> +                     FREIGHT_FOB_INSTALLMENTS: _("FOB - Freight value "
>> +                                                 "on installments"),
>> +                     FREIGHT_CIF_UNKNOWN: _("CIF - Freight value "
>> +                                            "is unknown"),
>> +                     FREIGHT_CIF_INVOICE: _("CIF - Freight value "
>> +                                            "highlighted on invoice")}
>
> Crie essas descrições como unicode: u"..."
>
>> @@ -210,7 +226,7 @@
>>         description = _(u'Freight for purchase %s' %
>> -                                self.purchase.get_order_number_str())
>> +                        self.purchase.get_order_number_str())
>
> Eu prefiro que essas mudanças que não tem muito a ver com o patch sejam evitadas. (a não ser que vc realmente já esteja editando as redondezas próximas)
>
> Elas só deixam o patch maior e mais complicado de revisar.
>
>> @@ -252,6 +268,28 @@
>>
>> +    def get_freight_types(self):
>> +        """Returns a list with available freight types"""
>> +        return [f for f in (self.FREIGHT_FOB_PAYMENT,
>> +                            self.FREIGHT_FOB_INSTALLMENTS,
>> +                            self.FREIGHT_CIF_UNKNOWN,
>> +                            self.FREIGHT_CIF_INVOICE)]
>
> Vc não precisar desse método (vou explicar no lugar onde vc usou ele). Mas apenas comentando já que ele está aqui:
>
> 1) ele poderia ser um classmethod. Dessa forma vc poderia usar ele mesmo sem uma instancia.
>
> 2) Vc poderia fazer simplesmente:
>
>         return (self.FREIGHT_FOB_PAYMENT,
>                 self.FREIGHT_FOB_INSTALLMENTS,
>                 self.FREIGHT_CIF_UNKNOWN,
>                 self.FREIGHT_CIF_INVOICE)
>
> Notou a diferença? vc criou uma tupla (um iterable), iterou sobre ele, criando uma lista (um outro iterable). Bastaria ter retornado essa primeira tupla.
>
> 3) Apenas para ilustrar, uma outra forma de fazer isso  (há casos em que isso é muito mais apropriado que esse):
>
> def foo():
>   for f in (self.FREIGHT, ...):
>      yield f
>
> Como dever de casa, fica ver o que ...

Read more...

lp:~bellini666/stoqlib/freight updated
3315. By Thiago Bellini

Add additional information for freight types on StartPurchaseStep gladefile.

3316. By Thiago Bellini

Code corrections and improvements.

Revision history for this message
Thiago Bellini (bellini666) wrote :

Correções apontadas feitas!

review: Needs Resubmitting
Revision history for this message
Ronaldo Maia (romaia) wrote :

O aprove que eu tinha colocado antes era para ter sido um needs fixing.

Agora está bom. Só falta corrigir os dois detalhes que apontei e pode aplicar na arvore principal.

review: Approve
lp:~bellini666/stoqlib/freight updated
3317. By Thiago Bellini

Changes to the Freight Combo behaviour. Makes it more "intelligent".

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/glade/ReceivingInvoiceSlave.glade'
2--- data/glade/ReceivingInvoiceSlave.glade 2009-09-17 16:21:42 +0000
3+++ data/glade/ReceivingInvoiceSlave.glade 2011-02-11 17:10:47 +0000
4@@ -5,6 +5,7 @@
5 <property name="allow_shrink">True</property>
6 <property name="default_height">250</property>
7 <property name="default_width">440</property>
8+ <property name="mnemonics_visible">False</property>
9 <property name="window_position">center-on-parent</property>
10 <child>
11 <widget class="GtkVBox" id="vbox1">
12@@ -14,7 +15,7 @@
13 <property name="border_width">2</property>
14 <property name="column_spacing">6</property>
15 <property name="n_columns">4</property>
16- <property name="n_rows">10</property>
17+ <property name="n_rows">9</property>
18 <property name="row_spacing">6</property>
19 <property name="visible">True</property>
20 <child>
21@@ -110,30 +111,23 @@
22 </packing>
23 </child>
24 <child>
25- <placeholder/>
26- <packing>
27- <property name="top_attach">7</property>
28- <property name="bottom_attach">8</property>
29- <property name="x_options">fill</property>
30- <property name="y_options"></property>
31- </packing>
32- </child>
33- <child>
34 <widget class="GtkLabel" id="label3">
35 <property name="label" context="yes" translatable="yes">Freight:</property>
36 <property name="visible">True</property>
37 <property name="xalign">1.0</property>
38 </widget>
39 <packing>
40+ <property name="bottom_attach">8</property>
41+ <property name="top_attach">7</property>
42+ <property name="x_options">fill</property>
43+ <property name="y_options"></property>
44+ </packing>
45+ </child>
46+ <child>
47+ <placeholder/>
48+ <packing>
49+ <property name="top_attach">8</property>
50 <property name="bottom_attach">9</property>
51- <property name="top_attach">8</property>
52- </packing>
53- </child>
54- <child>
55- <placeholder/>
56- <packing>
57- <property name="top_attach">9</property>
58- <property name="bottom_attach">10</property>
59 </packing>
60 </child>
61 <child>
62@@ -274,6 +268,21 @@
63 </packing>
64 </child>
65 <child>
66+ <widget class="ProxyComboBox" id="freight_combo">
67+ <property name="data_type">int</property>
68+ <property name="model_attribute">freight_type</property>
69+ <property name="visible">True</property>
70+ </widget>
71+ <packing>
72+ <property name="bottom_attach">8</property>
73+ <property name="left_attach">1</property>
74+ <property name="right_attach">2</property>
75+ <property name="top_attach">7</property>
76+ <property name="x_options">fill</property>
77+ <property name="y_options"></property>
78+ </packing>
79+ </child>
80+ <child>
81 <widget class="GtkHButtonBox" id="hbuttonbox1">
82 <property name="layout_style">start</property>
83 <property name="visible">True</property>
84@@ -282,31 +291,12 @@
85 <property name="is_focus">True</property>
86 <property name="label" context="yes" translatable="yes">Notes...</property>
87 <property name="visible">True</property>
88- <property name="xalign">1.0</property>
89+ <property name="xalign">0.0</property>
90 <property name="yalign">1.0</property>
91 </widget>
92 </child>
93 </widget>
94 <packing>
95- <property name="bottom_attach">8</property>
96- <property name="left_attach">1</property>
97- <property name="right_attach">2</property>
98- <property name="top_attach">7</property>
99- <property name="x_options">fill</property>
100- <property name="y_options"></property>
101- </packing>
102- </child>
103- <child>
104- <widget class="ProxyRadioButton" id="freight_in_installments">
105- <property name="active">False</property>
106- <property name="data_type">bool</property>
107- <property name="group">freight_in_payment</property>
108- <property name="is_focus">True</property>
109- <property name="label" context="yes" translatable="yes">Include freight value in installments</property>
110- <property name="model_attribute">freight_in_installments</property>
111- <property name="visible">True</property>
112- </widget>
113- <packing>
114 <property name="bottom_attach">9</property>
115 <property name="left_attach">1</property>
116 <property name="right_attach">2</property>
117@@ -315,21 +305,6 @@
118 </packing>
119 </child>
120 <child>
121- <widget class="ProxyRadioButton" id="freight_in_payment">
122- <property name="data_type">bool</property>
123- <property name="is_focus">True</property>
124- <property name="label" context="yes" translatable="yes">Create a separate payment for freight</property>
125- <property name="model_attribute">freight_in_payment</property>
126- <property name="visible">True</property>
127- </widget>
128- <packing>
129- <property name="bottom_attach">10</property>
130- <property name="left_attach">1</property>
131- <property name="right_attach">2</property>
132- <property name="top_attach">9</property>
133- </packing>
134- </child>
135- <child>
136 <widget class="ProxyLabel" id="kiwilabel4">
137 <property name="label" context="yes" translatable="yes">Products Total ($CURRENCY):</property>
138 <property name="model_attribute">kiwilabel4</property>
139@@ -459,15 +434,6 @@
140 </packing>
141 </child>
142 <child>
143- <placeholder/>
144- <packing>
145- <property name="left_attach">2</property>
146- <property name="right_attach">3</property>
147- <property name="top_attach">9</property>
148- <property name="bottom_attach">10</property>
149- </packing>
150- </child>
151- <child>
152 <widget class="ProxyLabel" id="products_total">
153 <property name="data_type">currency</property>
154 <property name="model_attribute">products_total</property>
155@@ -604,15 +570,6 @@
156 <property name="bottom_attach">9</property>
157 </packing>
158 </child>
159- <child>
160- <placeholder/>
161- <packing>
162- <property name="left_attach">3</property>
163- <property name="right_attach">4</property>
164- <property name="top_attach">9</property>
165- <property name="bottom_attach">10</property>
166- </packing>
167- </child>
168 </widget>
169 <packing>
170 <property name="expand">False</property>
171
172=== modified file 'data/glade/StartPurchaseStep.glade'
173--- data/glade/StartPurchaseStep.glade 2010-05-31 18:55:22 +0000
174+++ data/glade/StartPurchaseStep.glade 2011-02-11 17:10:47 +0000
175@@ -5,6 +5,7 @@
176 <property name="default_height">250</property>
177 <property name="default_width">440</property>
178 <property name="height_request">400</property>
179+ <property name="mnemonics_visible">False</property>
180 <property name="width_request">600</property>
181 <child>
182 <widget class="GtkVBox" id="vbox1">
183@@ -14,10 +15,10 @@
184 <child>
185 <widget class="GtkTable" id="table">
186 <property name="border_width">5</property>
187- <property name="column_spacing">5</property>
188+ <property name="column_spacing">6</property>
189 <property name="n_columns">5</property>
190 <property name="n_rows">5</property>
191- <property name="row_spacing">12</property>
192+ <property name="row_spacing">6</property>
193 <property name="visible">True</property>
194 <child>
195 <widget class="ProxyLabel" id="kiwilabel1">
196@@ -121,36 +122,36 @@
197 <child>
198 <widget class="GtkRadioButton" id="cif_radio">
199 <property name="is_focus">True</property>
200- <property name="label" context="yes" translatable="yes">CIF</property>
201+ <property name="label" context="yes" translatable="yes">CIF (Cost Insurance Freight)</property>
202 <property name="visible">True</property>
203 </widget>
204 </child>
205 <child>
206+ <placeholder/>
207+ <packing>
208+ <property name="position">1</property>
209+ </packing>
210+ </child>
211+ </widget>
212+ <packing>
213+ <property name="bottom_attach">4</property>
214+ <property name="left_attach">1</property>
215+ <property name="right_attach">2</property>
216+ <property name="top_attach">3</property>
217+ </packing>
218+ </child>
219+ <child>
220+ <widget class="GtkHBox" id="hbox2">
221+ <property name="spacing">6</property>
222+ <property name="visible">True</property>
223+ <child>
224 <widget class="GtkRadioButton" id="fob_radio">
225 <property name="active">False</property>
226 <property name="group">cif_radio</property>
227- <property name="label" context="yes" translatable="yes">FOB</property>
228+ <property name="is_focus">True</property>
229+ <property name="label" context="yes" translatable="yes">FOB (Free On Board)</property>
230 <property name="visible">True</property>
231 </widget>
232- <packing>
233- <property name="position">1</property>
234- </packing>
235- </child>
236- </widget>
237- <packing>
238- <property name="bottom_attach">4</property>
239- <property name="left_attach">1</property>
240- <property name="right_attach">2</property>
241- <property name="top_attach">3</property>
242- </packing>
243- </child>
244- <child>
245- <widget class="GtkHBox" id="hbox2">
246- <property name="spacing">6</property>
247- <property name="visible">True</property>
248- <child>
249- <placeholder/>
250- <packing/>
251 </child>
252 <child>
253 <placeholder/>
254@@ -198,6 +199,15 @@
255 </packing>
256 </child>
257 <child>
258+ <placeholder/>
259+ <packing>
260+ <property name="left_attach">2</property>
261+ <property name="right_attach">3</property>
262+ <property name="top_attach">3</property>
263+ <property name="bottom_attach">4</property>
264+ </packing>
265+ </child>
266+ <child>
267 <widget class="ProxyLabel" id="kiwilabel6">
268 <property name="data_type">unicode</property>
269 <property name="label" context="yes" translatable="yes">Expected Freight:</property>
270@@ -206,19 +216,10 @@
271 <property name="xalign">1.0</property>
272 </widget>
273 <packing>
274- <property name="bottom_attach">4</property>
275- <property name="left_attach">2</property>
276- <property name="right_attach">3</property>
277- <property name="top_attach">3</property>
278- </packing>
279- </child>
280- <child>
281- <placeholder/>
282- <packing>
283+ <property name="bottom_attach">5</property>
284 <property name="left_attach">2</property>
285 <property name="right_attach">3</property>
286 <property name="top_attach">4</property>
287- <property name="bottom_attach">5</property>
288 </packing>
289 </child>
290 <child>
291@@ -262,45 +263,62 @@
292 </packing>
293 </child>
294 <child>
295- <widget class="GtkHBox" id="hbox1">
296- <property name="spacing">6</property>
297+ <placeholder/>
298+ <packing>
299+ <property name="left_attach">3</property>
300+ <property name="right_attach">4</property>
301+ <property name="top_attach">3</property>
302+ <property name="bottom_attach">4</property>
303+ </packing>
304+ </child>
305+ <child>
306+ <widget class="GtkHBox" id="hbox3">
307 <property name="visible">True</property>
308 <child>
309- <widget class="ProxyLabel" id="kiwilabel7">
310- <property name="data_type">unicode</property>
311- <property name="label" context="yes" translatable="yes">$CURRENCY</property>
312- <property name="model_attribute">kiwilabel7</property>
313- <property name="visible">True</property>
314- <property name="xalign">1.0</property>
315- </widget>
316- </child>
317- <child>
318- <widget class="ProxyEntry" id="expected_freight">
319- <property name="data_type">Decimal</property>
320- <property name="model_attribute">expected_freight</property>
321- <property name="visible">True</property>
322- <property name="xalign">1.0</property>
323+ <widget class="GtkHBox" id="hbox1">
324+ <property name="spacing">6</property>
325+ <property name="visible">True</property>
326+ <child>
327+ <widget class="ProxyLabel" id="kiwilabel7">
328+ <property name="data_type">unicode</property>
329+ <property name="label" context="yes" translatable="yes">$CURRENCY</property>
330+ <property name="model_attribute">kiwilabel7</property>
331+ <property name="visible">True</property>
332+ <property name="xalign">1.0</property>
333+ </widget>
334+ </child>
335+ <child>
336+ <widget class="ProxyEntry" id="expected_freight">
337+ <property name="data_type">Decimal</property>
338+ <property name="model_attribute">expected_freight</property>
339+ <property name="visible">True</property>
340+ <property name="xalign">1.0</property>
341+ </widget>
342+ <packing>
343+ <property name="expand">False</property>
344+ <property name="position">1</property>
345+ </packing>
346+ </child>
347 </widget>
348 <packing>
349 <property name="expand">False</property>
350+ </packing>
351+ </child>
352+ <child>
353+ <widget class="ProxyLabel" id="kiwilabel8">
354+ <property name="model_attribute">kiwilabel8</property>
355+ <property name="visible">True</property>
356+ </widget>
357+ <packing>
358 <property name="position">1</property>
359 </packing>
360 </child>
361 </widget>
362 <packing>
363- <property name="bottom_attach">4</property>
364- <property name="left_attach">3</property>
365- <property name="right_attach">4</property>
366- <property name="top_attach">3</property>
367- </packing>
368- </child>
369- <child>
370- <placeholder/>
371- <packing>
372+ <property name="bottom_attach">5</property>
373 <property name="left_attach">3</property>
374 <property name="right_attach">4</property>
375 <property name="top_attach">4</property>
376- <property name="bottom_attach">5</property>
377 </packing>
378 </child>
379 <child>
380@@ -330,7 +348,7 @@
381 <child>
382 <widget class="ProxyLabel" id="kiwilabel13">
383 <property name="data_type">unicode</property>
384- <property name="model_attribute"></property>
385+ <property name="model_attribute">kiwilabel13</property>
386 <property name="visible">True</property>
387 </widget>
388 <packing>
389
390=== added file 'data/sql/patch-02-22.sql'
391--- data/sql/patch-02-22.sql 1970-01-01 00:00:00 +0000
392+++ data/sql/patch-02-22.sql 2011-02-11 17:10:47 +0000
393@@ -0,0 +1,7 @@
394+--
395+-- Add freight_type column on ReceivingOrder
396+--
397+
398+ALTER TABLE receiving_order
399+ ADD COLUMN freight_type integer DEFAULT 0;
400+
401
402=== modified file 'stoqlib/domain/receiving.py'
403--- stoqlib/domain/receiving.py 2011-02-08 14:21:07 +0000
404+++ stoqlib/domain/receiving.py 2011-02-11 17:10:47 +0000
405@@ -118,6 +118,7 @@
406 @ivar receival_date: Date that order has been closed.
407 @ivar confirm_date: Date that order was send to Stock application.
408 @ivar notes: Some optional additional information related to this order.
409+ @ivar freight_type: Type of freight
410 @ivar freight_total: Total of freight paid in receiving order.
411 @ivar surcharge_value:
412 @ivar discount_value: Discount value in receiving order's payment.
413@@ -129,10 +130,30 @@
414 (STATUS_PENDING,
415 STATUS_CLOSED) = range(2)
416
417+ (FREIGHT_FOB_PAYMENT,
418+ FREIGHT_FOB_INSTALLMENTS,
419+ FREIGHT_CIF_UNKNOWN,
420+ FREIGHT_CIF_INVOICE) = range(4)
421+
422+ freight_types = {FREIGHT_FOB_PAYMENT: _(u"FOB - Freight value "
423+ "on a new payment"),
424+ FREIGHT_FOB_INSTALLMENTS: _(u"FOB - Freight value "
425+ "on installments"),
426+ FREIGHT_CIF_UNKNOWN: _(u"CIF - Freight value "
427+ "is unknown"),
428+ FREIGHT_CIF_INVOICE: _(u"CIF - Freight value "
429+ "highlighted on invoice")}
430+
431+ FOB_FREIGHTS = (FREIGHT_FOB_PAYMENT,
432+ FREIGHT_FOB_INSTALLMENTS,)
433+ CIF_FREIGHTS = (FREIGHT_CIF_UNKNOWN,
434+ FREIGHT_CIF_INVOICE)
435+
436 status = IntCol(default=STATUS_PENDING)
437 receival_date = DateTimeCol(default=datetime.datetime.now)
438 confirm_date = DateTimeCol(default=None)
439 notes = UnicodeCol(default='')
440+ freight_type = IntCol(default=FREIGHT_FOB_PAYMENT)
441 freight_total = PriceCol(default=0)
442 surcharge_value = PriceCol(default=0)
443 discount_value = PriceCol(default=0)
444@@ -210,7 +231,7 @@
445 group = self.purchase.group
446
447 description = _(u'Freight for purchase %s' %
448- self.purchase.get_order_number_str())
449+ self.purchase.get_order_number_str())
450 out_payment = money_method.create_outpayment(
451 group, self.freight_total,
452 due_date=datetime.datetime.today(),
453@@ -300,7 +321,11 @@
454
455 if self.ipi_total:
456 total_surcharge += self.ipi_total
457- if self.freight_total:
458+
459+ # CIF freights don't generate payments.
460+ if (self.freight_total and
461+ self.freight_type not in (self.FREIGHT_CIF_UNKNOWN,
462+ self.FREIGHT_CIF_INVOICE)):
463 total_surcharge += self.freight_total
464
465 return currency(total_surcharge)
466@@ -332,6 +357,21 @@
467 # General methods
468 #
469
470+ def guess_freight_type(self):
471+ """Returns a freight_type based on the purchase's freight_type"""
472+ if self.purchase.freight_type == PurchaseOrder.FREIGHT_FOB:
473+ if self.purchase.is_paid():
474+ freight_type = ReceivingOrder.FREIGHT_FOB_PAYMENT
475+ else:
476+ freight_type = ReceivingOrder.FREIGHT_FOB_INSTALLMENTS
477+ elif self.purchase.freight_type == PurchaseOrder.FREIGHT_CIF:
478+ if not self.purchase.expected_freight:
479+ freight_type = ReceivingOrder.FREIGHT_CIF_UNKNOWN
480+ else:
481+ freight_type = ReceivingOrder.FREIGHT_CIF_INVOICE
482+
483+ return freight_type
484+
485 def _get_percentage_value(self, percentage):
486 if not percentage:
487 return currency(0)
488
489=== modified file 'stoqlib/gui/slaves/receivingslave.py'
490--- stoqlib/gui/slaves/receivingslave.py 2011-02-08 14:06:58 +0000
491+++ stoqlib/gui/slaves/receivingslave.py 2011-02-11 17:10:47 +0000
492@@ -38,11 +38,13 @@
493
494
495 class ReceivingInvoiceSlave(BaseEditorSlave):
496+
497 model_type = ReceivingOrder
498 gladefile = 'ReceivingInvoiceSlave'
499 proxy_widgets = ('transporter',
500 'responsible_name',
501 'products_total',
502+ 'freight_combo',
503 'freight',
504 'ipi',
505 'cfop',
506@@ -60,8 +62,6 @@
507 # BaseEditorSlave hooks
508 #
509
510- # We will avoid duplicating code like when setting up entry completions
511- # on bug 2275.
512 def _setup_transporter_entry(self):
513 # FIXME: Implement and use IDescribable on PersonAdaptToTransporter
514 table = PersonAdaptToTransporter
515@@ -69,31 +69,57 @@
516 items = [(t.person.name, t) for t in transporters]
517 self.transporter.prefill(items)
518
519+ def _setup_freight_combo(self):
520+ freight_items = [(value, key) for (key, value) in
521+ ReceivingOrder.freight_types.items()]
522+
523+ # If the purchase's installments are paid, we cannot modify them.
524+ if (self.model.purchase.is_paid() and not self.visual_mode):
525+ ro = ReceivingOrder
526+ freight_items.remove((ro.freight_types[ro.FREIGHT_FOB_INSTALLMENTS],
527+ ro.FREIGHT_FOB_INSTALLMENTS))
528+
529+ # Disconnect that callback to prevent an AttributeError
530+ # caused by the lack of a proxy.
531+ handler_func = self.after_freight_combo__content_changed
532+ self.freight_combo.handler_block_by_func(handler_func)
533+
534+ self.freight_combo.prefill(freight_items)
535+
536+ self.freight_combo.handler_unblock_by_func(handler_func)
537+
538 def _setup_widgets(self):
539 self.total.set_bold(True)
540- purchase_widgets = (self.purchase_number_label,
541- self.purchase_supplier_label,
542- self.order_number, self.supplier_label)
543- if not self.model.purchase:
544- for widget in purchase_widgets:
545+
546+ purchase = self.model.purchase
547+ if not purchase:
548+ for widget in (self.purchase_number_label,
549+ self.purchase_supplier_label,
550+ self.order_number, self.supplier_label):
551 widget.hide()
552- if self.model.purchase.is_paid():
553- for widget in [self.ipi, self.discount_value, self.icms_total,
554- self.secure_value, self.expense_value,
555- self.freight_in_installments]:
556+ elif purchase and purchase.is_paid():
557+ for widget in (self.ipi, self.discount_value, self.icms_total,
558+ self.secure_value, self.expense_value):
559 widget.set_sensitive(False)
560
561 self._setup_transporter_entry()
562+ self._setup_freight_combo()
563+
564+ # CFOP entry setup
565 cfop_items = [(item.get_description(), item)
566- for item in CfopData.select(connection=self.conn)]
567+ for item in CfopData.select(connection=self.conn)]
568 self.cfop.prefill(cfop_items)
569- # The user should not be allowed to change the transporter,
570- # if it's already set.
571- if self.model.transporter:
572- self.transporter.set_sensitive(False)
573
574 def create_freight_payment(self):
575- return self.freight_in_payment.get_active()
576+ """Tells if we should create a separate payment for freight or not
577+
578+ It should return True or False. If True is returned, a separate payment
579+ will be created for freight. If not, it'll be included on installments.
580+ """
581+ freight_type = self.freight_combo.read()
582+ if freight_type == self.model.FREIGHT_FOB_PAYMENT:
583+ return True
584+ return False
585
586 #
587 # BaseEditorSlave hooks
588@@ -101,35 +127,50 @@
589
590 def update_visual_mode(self):
591 self.notes_button.hide()
592- self.freight_in_installments.set_sensitive(False)
593- self.freight_in_payment.set_sensitive(False)
594+ self.freight_combo.set_sensitive(False)
595
596 def setup_proxies(self):
597 self._setup_widgets()
598 self.proxy = self.add_proxy(self.model,
599 ReceivingInvoiceSlave.proxy_widgets)
600+
601 self.model.invoice_total = self.model.get_products_total()
602- self.proxy.update('total')
603+
604 purchase = self.model.purchase
605 if purchase:
606- transporter = purchase.transporter
607- self.model.transporter = transporter
608- self.proxy.update('transporter')
609+ if not self.visual_mode:
610+ # These values are duplicates from the purchase. If we are
611+ # visualising the order, the value should be it's own, not the
612+ # purchase ones.
613+ self.freight_combo.update(self.model.guess_freight_type())
614+ self.freight.update(purchase.expected_freight)
615+
616 self.model.supplier = purchase.supplier
617- self.model.freight_total = purchase.expected_freight
618- self.proxy.update('freight_total')
619+ self.transporter.update(purchase.transporter)
620+
621+ self.proxy.update('total')
622
623 #
624 # Callbacks
625 #
626
627+ def _positive_validator(self, widget, value):
628+ if value < 0:
629+ return ValidationError(_("This field cannot be negative"))
630+
631+ on_freight__validate = _positive_validator
632+ on_ipi__validate = _positive_validator
633+ on_icms_total__validate = _positive_validator
634+ on_secure_value__validate = _positive_validator
635+ on_expense_value__validate = _positive_validator
636+
637 def on_notes_button__clicked(self, *args):
638 run_dialog(NoteEditor, self, self.conn, self.model, 'notes',
639 title=_('Additional Information'))
640
641 def on_invoice_number__validate(self, widget, value):
642 if value < 1 or value > 999999:
643- return ValidationError(_("Receving order number must be "
644+ return ValidationError(_("Receiving order number must be "
645 "between 1 and 999999"))
646
647 order_count = ReceivingOrder.selectBy(invoice_number=value,
648@@ -140,15 +181,21 @@
649 return ValidationError(_(u'Invoice %d already exists for '
650 'supplier %s.' % (value, supplier_name,)))
651
652- def _positive_validator(self, widget, value):
653- if value < 0:
654- return ValidationError(_("This field cannot be negative"))
655-
656- on_freight__validate = _positive_validator
657- on_ipi__validate = _positive_validator
658- on_icms_total__validate = _positive_validator
659- on_secure_value__validate = _positive_validator
660- on_expense_value__validate = _positive_validator
661+ def after_freight_combo__content_changed(self, widget):
662+ value = widget.read()
663+
664+ if value == ReceivingOrder.FREIGHT_CIF_UNKNOWN:
665+ self.freight.update(0)
666+ self.freight.set_sensitive(False)
667+ else:
668+ if not self.visual_mode:
669+ self.freight.set_sensitive(True)
670+ if (not self.model.freight_total and
671+ value in ReceivingOrder.FOB_FREIGHTS):
672+ # Restore the freight value to the purchase expected one.
673+ self.freight.update(self.model.purchase.expected_freight)
674+
675+ self.proxy.update('total')
676
677 def after_freight__content_changed(self, widget):
678 try:
679@@ -157,7 +204,7 @@
680 value = ValueUnset
681
682 if value is ValueUnset:
683- self.model.freight = 0
684+ self.model.freight_total = 0
685 self.proxy.update('total')
686
687 def after_ipi__content_changed(self, widget):

Subscribers

People subscribed via source and target branches