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
=== modified file 'data/glade/ReceivingInvoiceSlave.glade'
--- data/glade/ReceivingInvoiceSlave.glade 2009-09-17 16:21:42 +0000
+++ data/glade/ReceivingInvoiceSlave.glade 2011-02-11 17:10:47 +0000
@@ -5,6 +5,7 @@
5 <property name="allow_shrink">True</property>5 <property name="allow_shrink">True</property>
6 <property name="default_height">250</property>6 <property name="default_height">250</property>
7 <property name="default_width">440</property>7 <property name="default_width">440</property>
8 <property name="mnemonics_visible">False</property>
8 <property name="window_position">center-on-parent</property>9 <property name="window_position">center-on-parent</property>
9 <child>10 <child>
10 <widget class="GtkVBox" id="vbox1">11 <widget class="GtkVBox" id="vbox1">
@@ -14,7 +15,7 @@
14 <property name="border_width">2</property>15 <property name="border_width">2</property>
15 <property name="column_spacing">6</property>16 <property name="column_spacing">6</property>
16 <property name="n_columns">4</property>17 <property name="n_columns">4</property>
17 <property name="n_rows">10</property>18 <property name="n_rows">9</property>
18 <property name="row_spacing">6</property>19 <property name="row_spacing">6</property>
19 <property name="visible">True</property>20 <property name="visible">True</property>
20 <child>21 <child>
@@ -110,30 +111,23 @@
110 </packing>111 </packing>
111 </child>112 </child>
112 <child>113 <child>
113 <placeholder/>
114 <packing>
115 <property name="top_attach">7</property>
116 <property name="bottom_attach">8</property>
117 <property name="x_options">fill</property>
118 <property name="y_options"></property>
119 </packing>
120 </child>
121 <child>
122 <widget class="GtkLabel" id="label3">114 <widget class="GtkLabel" id="label3">
123 <property name="label" context="yes" translatable="yes">Freight:</property>115 <property name="label" context="yes" translatable="yes">Freight:</property>
124 <property name="visible">True</property>116 <property name="visible">True</property>
125 <property name="xalign">1.0</property>117 <property name="xalign">1.0</property>
126 </widget>118 </widget>
127 <packing>119 <packing>
120 <property name="bottom_attach">8</property>
121 <property name="top_attach">7</property>
122 <property name="x_options">fill</property>
123 <property name="y_options"></property>
124 </packing>
125 </child>
126 <child>
127 <placeholder/>
128 <packing>
129 <property name="top_attach">8</property>
128 <property name="bottom_attach">9</property>130 <property name="bottom_attach">9</property>
129 <property name="top_attach">8</property>
130 </packing>
131 </child>
132 <child>
133 <placeholder/>
134 <packing>
135 <property name="top_attach">9</property>
136 <property name="bottom_attach">10</property>
137 </packing>131 </packing>
138 </child>132 </child>
139 <child>133 <child>
@@ -274,6 +268,21 @@
274 </packing>268 </packing>
275 </child>269 </child>
276 <child>270 <child>
271 <widget class="ProxyComboBox" id="freight_combo">
272 <property name="data_type">int</property>
273 <property name="model_attribute">freight_type</property>
274 <property name="visible">True</property>
275 </widget>
276 <packing>
277 <property name="bottom_attach">8</property>
278 <property name="left_attach">1</property>
279 <property name="right_attach">2</property>
280 <property name="top_attach">7</property>
281 <property name="x_options">fill</property>
282 <property name="y_options"></property>
283 </packing>
284 </child>
285 <child>
277 <widget class="GtkHButtonBox" id="hbuttonbox1">286 <widget class="GtkHButtonBox" id="hbuttonbox1">
278 <property name="layout_style">start</property>287 <property name="layout_style">start</property>
279 <property name="visible">True</property>288 <property name="visible">True</property>
@@ -282,31 +291,12 @@
282 <property name="is_focus">True</property>291 <property name="is_focus">True</property>
283 <property name="label" context="yes" translatable="yes">Notes...</property>292 <property name="label" context="yes" translatable="yes">Notes...</property>
284 <property name="visible">True</property>293 <property name="visible">True</property>
285 <property name="xalign">1.0</property>294 <property name="xalign">0.0</property>
286 <property name="yalign">1.0</property>295 <property name="yalign">1.0</property>
287 </widget>296 </widget>
288 </child>297 </child>
289 </widget>298 </widget>
290 <packing>299 <packing>
291 <property name="bottom_attach">8</property>
292 <property name="left_attach">1</property>
293 <property name="right_attach">2</property>
294 <property name="top_attach">7</property>
295 <property name="x_options">fill</property>
296 <property name="y_options"></property>
297 </packing>
298 </child>
299 <child>
300 <widget class="ProxyRadioButton" id="freight_in_installments">
301 <property name="active">False</property>
302 <property name="data_type">bool</property>
303 <property name="group">freight_in_payment</property>
304 <property name="is_focus">True</property>
305 <property name="label" context="yes" translatable="yes">Include freight value in installments</property>
306 <property name="model_attribute">freight_in_installments</property>
307 <property name="visible">True</property>
308 </widget>
309 <packing>
310 <property name="bottom_attach">9</property>300 <property name="bottom_attach">9</property>
311 <property name="left_attach">1</property>301 <property name="left_attach">1</property>
312 <property name="right_attach">2</property>302 <property name="right_attach">2</property>
@@ -315,21 +305,6 @@
315 </packing>305 </packing>
316 </child>306 </child>
317 <child>307 <child>
318 <widget class="ProxyRadioButton" id="freight_in_payment">
319 <property name="data_type">bool</property>
320 <property name="is_focus">True</property>
321 <property name="label" context="yes" translatable="yes">Create a separate payment for freight</property>
322 <property name="model_attribute">freight_in_payment</property>
323 <property name="visible">True</property>
324 </widget>
325 <packing>
326 <property name="bottom_attach">10</property>
327 <property name="left_attach">1</property>
328 <property name="right_attach">2</property>
329 <property name="top_attach">9</property>
330 </packing>
331 </child>
332 <child>
333 <widget class="ProxyLabel" id="kiwilabel4">308 <widget class="ProxyLabel" id="kiwilabel4">
334 <property name="label" context="yes" translatable="yes">Products Total ($CURRENCY):</property>309 <property name="label" context="yes" translatable="yes">Products Total ($CURRENCY):</property>
335 <property name="model_attribute">kiwilabel4</property>310 <property name="model_attribute">kiwilabel4</property>
@@ -459,15 +434,6 @@
459 </packing>434 </packing>
460 </child>435 </child>
461 <child>436 <child>
462 <placeholder/>
463 <packing>
464 <property name="left_attach">2</property>
465 <property name="right_attach">3</property>
466 <property name="top_attach">9</property>
467 <property name="bottom_attach">10</property>
468 </packing>
469 </child>
470 <child>
471 <widget class="ProxyLabel" id="products_total">437 <widget class="ProxyLabel" id="products_total">
472 <property name="data_type">currency</property>438 <property name="data_type">currency</property>
473 <property name="model_attribute">products_total</property>439 <property name="model_attribute">products_total</property>
@@ -604,15 +570,6 @@
604 <property name="bottom_attach">9</property>570 <property name="bottom_attach">9</property>
605 </packing>571 </packing>
606 </child>572 </child>
607 <child>
608 <placeholder/>
609 <packing>
610 <property name="left_attach">3</property>
611 <property name="right_attach">4</property>
612 <property name="top_attach">9</property>
613 <property name="bottom_attach">10</property>
614 </packing>
615 </child>
616 </widget>573 </widget>
617 <packing>574 <packing>
618 <property name="expand">False</property>575 <property name="expand">False</property>
619576
=== modified file 'data/glade/StartPurchaseStep.glade'
--- data/glade/StartPurchaseStep.glade 2010-05-31 18:55:22 +0000
+++ data/glade/StartPurchaseStep.glade 2011-02-11 17:10:47 +0000
@@ -5,6 +5,7 @@
5 <property name="default_height">250</property>5 <property name="default_height">250</property>
6 <property name="default_width">440</property>6 <property name="default_width">440</property>
7 <property name="height_request">400</property>7 <property name="height_request">400</property>
8 <property name="mnemonics_visible">False</property>
8 <property name="width_request">600</property>9 <property name="width_request">600</property>
9 <child>10 <child>
10 <widget class="GtkVBox" id="vbox1">11 <widget class="GtkVBox" id="vbox1">
@@ -14,10 +15,10 @@
14 <child>15 <child>
15 <widget class="GtkTable" id="table">16 <widget class="GtkTable" id="table">
16 <property name="border_width">5</property>17 <property name="border_width">5</property>
17 <property name="column_spacing">5</property>18 <property name="column_spacing">6</property>
18 <property name="n_columns">5</property>19 <property name="n_columns">5</property>
19 <property name="n_rows">5</property>20 <property name="n_rows">5</property>
20 <property name="row_spacing">12</property>21 <property name="row_spacing">6</property>
21 <property name="visible">True</property>22 <property name="visible">True</property>
22 <child>23 <child>
23 <widget class="ProxyLabel" id="kiwilabel1">24 <widget class="ProxyLabel" id="kiwilabel1">
@@ -121,36 +122,36 @@
121 <child>122 <child>
122 <widget class="GtkRadioButton" id="cif_radio">123 <widget class="GtkRadioButton" id="cif_radio">
123 <property name="is_focus">True</property>124 <property name="is_focus">True</property>
124 <property name="label" context="yes" translatable="yes">CIF</property>125 <property name="label" context="yes" translatable="yes">CIF (Cost Insurance Freight)</property>
125 <property name="visible">True</property>126 <property name="visible">True</property>
126 </widget>127 </widget>
127 </child>128 </child>
128 <child>129 <child>
130 <placeholder/>
131 <packing>
132 <property name="position">1</property>
133 </packing>
134 </child>
135 </widget>
136 <packing>
137 <property name="bottom_attach">4</property>
138 <property name="left_attach">1</property>
139 <property name="right_attach">2</property>
140 <property name="top_attach">3</property>
141 </packing>
142 </child>
143 <child>
144 <widget class="GtkHBox" id="hbox2">
145 <property name="spacing">6</property>
146 <property name="visible">True</property>
147 <child>
129 <widget class="GtkRadioButton" id="fob_radio">148 <widget class="GtkRadioButton" id="fob_radio">
130 <property name="active">False</property>149 <property name="active">False</property>
131 <property name="group">cif_radio</property>150 <property name="group">cif_radio</property>
132 <property name="label" context="yes" translatable="yes">FOB</property>151 <property name="is_focus">True</property>
152 <property name="label" context="yes" translatable="yes">FOB (Free On Board)</property>
133 <property name="visible">True</property>153 <property name="visible">True</property>
134 </widget>154 </widget>
135 <packing>
136 <property name="position">1</property>
137 </packing>
138 </child>
139 </widget>
140 <packing>
141 <property name="bottom_attach">4</property>
142 <property name="left_attach">1</property>
143 <property name="right_attach">2</property>
144 <property name="top_attach">3</property>
145 </packing>
146 </child>
147 <child>
148 <widget class="GtkHBox" id="hbox2">
149 <property name="spacing">6</property>
150 <property name="visible">True</property>
151 <child>
152 <placeholder/>
153 <packing/>
154 </child>155 </child>
155 <child>156 <child>
156 <placeholder/>157 <placeholder/>
@@ -198,6 +199,15 @@
198 </packing>199 </packing>
199 </child>200 </child>
200 <child>201 <child>
202 <placeholder/>
203 <packing>
204 <property name="left_attach">2</property>
205 <property name="right_attach">3</property>
206 <property name="top_attach">3</property>
207 <property name="bottom_attach">4</property>
208 </packing>
209 </child>
210 <child>
201 <widget class="ProxyLabel" id="kiwilabel6">211 <widget class="ProxyLabel" id="kiwilabel6">
202 <property name="data_type">unicode</property>212 <property name="data_type">unicode</property>
203 <property name="label" context="yes" translatable="yes">Expected Freight:</property>213 <property name="label" context="yes" translatable="yes">Expected Freight:</property>
@@ -206,19 +216,10 @@
206 <property name="xalign">1.0</property>216 <property name="xalign">1.0</property>
207 </widget>217 </widget>
208 <packing>218 <packing>
209 <property name="bottom_attach">4</property>219 <property name="bottom_attach">5</property>
210 <property name="left_attach">2</property>
211 <property name="right_attach">3</property>
212 <property name="top_attach">3</property>
213 </packing>
214 </child>
215 <child>
216 <placeholder/>
217 <packing>
218 <property name="left_attach">2</property>220 <property name="left_attach">2</property>
219 <property name="right_attach">3</property>221 <property name="right_attach">3</property>
220 <property name="top_attach">4</property>222 <property name="top_attach">4</property>
221 <property name="bottom_attach">5</property>
222 </packing>223 </packing>
223 </child>224 </child>
224 <child>225 <child>
@@ -262,45 +263,62 @@
262 </packing>263 </packing>
263 </child>264 </child>
264 <child>265 <child>
265 <widget class="GtkHBox" id="hbox1">266 <placeholder/>
266 <property name="spacing">6</property>267 <packing>
268 <property name="left_attach">3</property>
269 <property name="right_attach">4</property>
270 <property name="top_attach">3</property>
271 <property name="bottom_attach">4</property>
272 </packing>
273 </child>
274 <child>
275 <widget class="GtkHBox" id="hbox3">
267 <property name="visible">True</property>276 <property name="visible">True</property>
268 <child>277 <child>
269 <widget class="ProxyLabel" id="kiwilabel7">278 <widget class="GtkHBox" id="hbox1">
270 <property name="data_type">unicode</property>279 <property name="spacing">6</property>
271 <property name="label" context="yes" translatable="yes">$CURRENCY</property>280 <property name="visible">True</property>
272 <property name="model_attribute">kiwilabel7</property>281 <child>
273 <property name="visible">True</property>282 <widget class="ProxyLabel" id="kiwilabel7">
274 <property name="xalign">1.0</property>283 <property name="data_type">unicode</property>
275 </widget>284 <property name="label" context="yes" translatable="yes">$CURRENCY</property>
276 </child>285 <property name="model_attribute">kiwilabel7</property>
277 <child>286 <property name="visible">True</property>
278 <widget class="ProxyEntry" id="expected_freight">287 <property name="xalign">1.0</property>
279 <property name="data_type">Decimal</property>288 </widget>
280 <property name="model_attribute">expected_freight</property>289 </child>
281 <property name="visible">True</property>290 <child>
282 <property name="xalign">1.0</property>291 <widget class="ProxyEntry" id="expected_freight">
292 <property name="data_type">Decimal</property>
293 <property name="model_attribute">expected_freight</property>
294 <property name="visible">True</property>
295 <property name="xalign">1.0</property>
296 </widget>
297 <packing>
298 <property name="expand">False</property>
299 <property name="position">1</property>
300 </packing>
301 </child>
283 </widget>302 </widget>
284 <packing>303 <packing>
285 <property name="expand">False</property>304 <property name="expand">False</property>
305 </packing>
306 </child>
307 <child>
308 <widget class="ProxyLabel" id="kiwilabel8">
309 <property name="model_attribute">kiwilabel8</property>
310 <property name="visible">True</property>
311 </widget>
312 <packing>
286 <property name="position">1</property>313 <property name="position">1</property>
287 </packing>314 </packing>
288 </child>315 </child>
289 </widget>316 </widget>
290 <packing>317 <packing>
291 <property name="bottom_attach">4</property>318 <property name="bottom_attach">5</property>
292 <property name="left_attach">3</property>
293 <property name="right_attach">4</property>
294 <property name="top_attach">3</property>
295 </packing>
296 </child>
297 <child>
298 <placeholder/>
299 <packing>
300 <property name="left_attach">3</property>319 <property name="left_attach">3</property>
301 <property name="right_attach">4</property>320 <property name="right_attach">4</property>
302 <property name="top_attach">4</property>321 <property name="top_attach">4</property>
303 <property name="bottom_attach">5</property>
304 </packing>322 </packing>
305 </child>323 </child>
306 <child>324 <child>
@@ -330,7 +348,7 @@
330 <child>348 <child>
331 <widget class="ProxyLabel" id="kiwilabel13">349 <widget class="ProxyLabel" id="kiwilabel13">
332 <property name="data_type">unicode</property>350 <property name="data_type">unicode</property>
333 <property name="model_attribute"></property>351 <property name="model_attribute">kiwilabel13</property>
334 <property name="visible">True</property>352 <property name="visible">True</property>
335 </widget>353 </widget>
336 <packing>354 <packing>
337355
=== added file 'data/sql/patch-02-22.sql'
--- data/sql/patch-02-22.sql 1970-01-01 00:00:00 +0000
+++ data/sql/patch-02-22.sql 2011-02-11 17:10:47 +0000
@@ -0,0 +1,7 @@
1--
2-- Add freight_type column on ReceivingOrder
3--
4
5ALTER TABLE receiving_order
6 ADD COLUMN freight_type integer DEFAULT 0;
7
08
=== modified file 'stoqlib/domain/receiving.py'
--- stoqlib/domain/receiving.py 2011-02-08 14:21:07 +0000
+++ stoqlib/domain/receiving.py 2011-02-11 17:10:47 +0000
@@ -118,6 +118,7 @@
118 @ivar receival_date: Date that order has been closed.118 @ivar receival_date: Date that order has been closed.
119 @ivar confirm_date: Date that order was send to Stock application.119 @ivar confirm_date: Date that order was send to Stock application.
120 @ivar notes: Some optional additional information related to this order.120 @ivar notes: Some optional additional information related to this order.
121 @ivar freight_type: Type of freight
121 @ivar freight_total: Total of freight paid in receiving order.122 @ivar freight_total: Total of freight paid in receiving order.
122 @ivar surcharge_value:123 @ivar surcharge_value:
123 @ivar discount_value: Discount value in receiving order's payment.124 @ivar discount_value: Discount value in receiving order's payment.
@@ -129,10 +130,30 @@
129 (STATUS_PENDING,130 (STATUS_PENDING,
130 STATUS_CLOSED) = range(2)131 STATUS_CLOSED) = range(2)
131132
133 (FREIGHT_FOB_PAYMENT,
134 FREIGHT_FOB_INSTALLMENTS,
135 FREIGHT_CIF_UNKNOWN,
136 FREIGHT_CIF_INVOICE) = range(4)
137
138 freight_types = {FREIGHT_FOB_PAYMENT: _(u"FOB - Freight value "
139 "on a new payment"),
140 FREIGHT_FOB_INSTALLMENTS: _(u"FOB - Freight value "
141 "on installments"),
142 FREIGHT_CIF_UNKNOWN: _(u"CIF - Freight value "
143 "is unknown"),
144 FREIGHT_CIF_INVOICE: _(u"CIF - Freight value "
145 "highlighted on invoice")}
146
147 FOB_FREIGHTS = (FREIGHT_FOB_PAYMENT,
148 FREIGHT_FOB_INSTALLMENTS,)
149 CIF_FREIGHTS = (FREIGHT_CIF_UNKNOWN,
150 FREIGHT_CIF_INVOICE)
151
132 status = IntCol(default=STATUS_PENDING)152 status = IntCol(default=STATUS_PENDING)
133 receival_date = DateTimeCol(default=datetime.datetime.now)153 receival_date = DateTimeCol(default=datetime.datetime.now)
134 confirm_date = DateTimeCol(default=None)154 confirm_date = DateTimeCol(default=None)
135 notes = UnicodeCol(default='')155 notes = UnicodeCol(default='')
156 freight_type = IntCol(default=FREIGHT_FOB_PAYMENT)
136 freight_total = PriceCol(default=0)157 freight_total = PriceCol(default=0)
137 surcharge_value = PriceCol(default=0)158 surcharge_value = PriceCol(default=0)
138 discount_value = PriceCol(default=0)159 discount_value = PriceCol(default=0)
@@ -210,7 +231,7 @@
210 group = self.purchase.group231 group = self.purchase.group
211232
212 description = _(u'Freight for purchase %s' %233 description = _(u'Freight for purchase %s' %
213 self.purchase.get_order_number_str())234 self.purchase.get_order_number_str())
214 out_payment = money_method.create_outpayment(235 out_payment = money_method.create_outpayment(
215 group, self.freight_total,236 group, self.freight_total,
216 due_date=datetime.datetime.today(),237 due_date=datetime.datetime.today(),
@@ -300,7 +321,11 @@
300321
301 if self.ipi_total:322 if self.ipi_total:
302 total_surcharge += self.ipi_total323 total_surcharge += self.ipi_total
303 if self.freight_total:324
325 # CIF freights don't generate payments.
326 if (self.freight_total and
327 self.freight_type not in (self.FREIGHT_CIF_UNKNOWN,
328 self.FREIGHT_CIF_INVOICE)):
304 total_surcharge += self.freight_total329 total_surcharge += self.freight_total
305330
306 return currency(total_surcharge)331 return currency(total_surcharge)
@@ -332,6 +357,21 @@
332 # General methods357 # General methods
333 #358 #
334359
360 def guess_freight_type(self):
361 """Returns a freight_type based on the purchase's freight_type"""
362 if self.purchase.freight_type == PurchaseOrder.FREIGHT_FOB:
363 if self.purchase.is_paid():
364 freight_type = ReceivingOrder.FREIGHT_FOB_PAYMENT
365 else:
366 freight_type = ReceivingOrder.FREIGHT_FOB_INSTALLMENTS
367 elif self.purchase.freight_type == PurchaseOrder.FREIGHT_CIF:
368 if not self.purchase.expected_freight:
369 freight_type = ReceivingOrder.FREIGHT_CIF_UNKNOWN
370 else:
371 freight_type = ReceivingOrder.FREIGHT_CIF_INVOICE
372
373 return freight_type
374
335 def _get_percentage_value(self, percentage):375 def _get_percentage_value(self, percentage):
336 if not percentage:376 if not percentage:
337 return currency(0)377 return currency(0)
338378
=== modified file 'stoqlib/gui/slaves/receivingslave.py'
--- stoqlib/gui/slaves/receivingslave.py 2011-02-08 14:06:58 +0000
+++ stoqlib/gui/slaves/receivingslave.py 2011-02-11 17:10:47 +0000
@@ -38,11 +38,13 @@
3838
3939
40class ReceivingInvoiceSlave(BaseEditorSlave):40class ReceivingInvoiceSlave(BaseEditorSlave):
41
41 model_type = ReceivingOrder42 model_type = ReceivingOrder
42 gladefile = 'ReceivingInvoiceSlave'43 gladefile = 'ReceivingInvoiceSlave'
43 proxy_widgets = ('transporter',44 proxy_widgets = ('transporter',
44 'responsible_name',45 'responsible_name',
45 'products_total',46 'products_total',
47 'freight_combo',
46 'freight',48 'freight',
47 'ipi',49 'ipi',
48 'cfop',50 'cfop',
@@ -60,8 +62,6 @@
60 # BaseEditorSlave hooks62 # BaseEditorSlave hooks
61 #63 #
6264
63 # We will avoid duplicating code like when setting up entry completions
64 # on bug 2275.
65 def _setup_transporter_entry(self):65 def _setup_transporter_entry(self):
66 # FIXME: Implement and use IDescribable on PersonAdaptToTransporter66 # FIXME: Implement and use IDescribable on PersonAdaptToTransporter
67 table = PersonAdaptToTransporter67 table = PersonAdaptToTransporter
@@ -69,31 +69,57 @@
69 items = [(t.person.name, t) for t in transporters]69 items = [(t.person.name, t) for t in transporters]
70 self.transporter.prefill(items)70 self.transporter.prefill(items)
7171
72 def _setup_freight_combo(self):
73 freight_items = [(value, key) for (key, value) in
74 ReceivingOrder.freight_types.items()]
75
76 # If the purchase's installments are paid, we cannot modify them.
77 if (self.model.purchase.is_paid() and not self.visual_mode):
78 ro = ReceivingOrder
79 freight_items.remove((ro.freight_types[ro.FREIGHT_FOB_INSTALLMENTS],
80 ro.FREIGHT_FOB_INSTALLMENTS))
81
82 # Disconnect that callback to prevent an AttributeError
83 # caused by the lack of a proxy.
84 handler_func = self.after_freight_combo__content_changed
85 self.freight_combo.handler_block_by_func(handler_func)
86
87 self.freight_combo.prefill(freight_items)
88
89 self.freight_combo.handler_unblock_by_func(handler_func)
90
72 def _setup_widgets(self):91 def _setup_widgets(self):
73 self.total.set_bold(True)92 self.total.set_bold(True)
74 purchase_widgets = (self.purchase_number_label,93
75 self.purchase_supplier_label,94 purchase = self.model.purchase
76 self.order_number, self.supplier_label)95 if not purchase:
77 if not self.model.purchase:96 for widget in (self.purchase_number_label,
78 for widget in purchase_widgets:97 self.purchase_supplier_label,
98 self.order_number, self.supplier_label):
79 widget.hide()99 widget.hide()
80 if self.model.purchase.is_paid():100 elif purchase and purchase.is_paid():
81 for widget in [self.ipi, self.discount_value, self.icms_total,101 for widget in (self.ipi, self.discount_value, self.icms_total,
82 self.secure_value, self.expense_value,102 self.secure_value, self.expense_value):
83 self.freight_in_installments]:
84 widget.set_sensitive(False)103 widget.set_sensitive(False)
85104
86 self._setup_transporter_entry()105 self._setup_transporter_entry()
106 self._setup_freight_combo()
107
108 # CFOP entry setup
87 cfop_items = [(item.get_description(), item)109 cfop_items = [(item.get_description(), item)
88 for item in CfopData.select(connection=self.conn)]110 for item in CfopData.select(connection=self.conn)]
89 self.cfop.prefill(cfop_items)111 self.cfop.prefill(cfop_items)
90 # The user should not be allowed to change the transporter,
91 # if it's already set.
92 if self.model.transporter:
93 self.transporter.set_sensitive(False)
94112
95 def create_freight_payment(self):113 def create_freight_payment(self):
96 return self.freight_in_payment.get_active()114 """Tells if we should create a separate payment for freight or not
115
116 It should return True or False. If True is returned, a separate payment
117 will be created for freight. If not, it'll be included on installments.
118 """
119 freight_type = self.freight_combo.read()
120 if freight_type == self.model.FREIGHT_FOB_PAYMENT:
121 return True
122 return False
97123
98 #124 #
99 # BaseEditorSlave hooks125 # BaseEditorSlave hooks
@@ -101,35 +127,50 @@
101127
102 def update_visual_mode(self):128 def update_visual_mode(self):
103 self.notes_button.hide()129 self.notes_button.hide()
104 self.freight_in_installments.set_sensitive(False)130 self.freight_combo.set_sensitive(False)
105 self.freight_in_payment.set_sensitive(False)
106131
107 def setup_proxies(self):132 def setup_proxies(self):
108 self._setup_widgets()133 self._setup_widgets()
109 self.proxy = self.add_proxy(self.model,134 self.proxy = self.add_proxy(self.model,
110 ReceivingInvoiceSlave.proxy_widgets)135 ReceivingInvoiceSlave.proxy_widgets)
136
111 self.model.invoice_total = self.model.get_products_total()137 self.model.invoice_total = self.model.get_products_total()
112 self.proxy.update('total')138
113 purchase = self.model.purchase139 purchase = self.model.purchase
114 if purchase:140 if purchase:
115 transporter = purchase.transporter141 if not self.visual_mode:
116 self.model.transporter = transporter142 # These values are duplicates from the purchase. If we are
117 self.proxy.update('transporter')143 # visualising the order, the value should be it's own, not the
144 # purchase ones.
145 self.freight_combo.update(self.model.guess_freight_type())
146 self.freight.update(purchase.expected_freight)
147
118 self.model.supplier = purchase.supplier148 self.model.supplier = purchase.supplier
119 self.model.freight_total = purchase.expected_freight149 self.transporter.update(purchase.transporter)
120 self.proxy.update('freight_total')150
151 self.proxy.update('total')
121152
122 #153 #
123 # Callbacks154 # Callbacks
124 #155 #
125156
157 def _positive_validator(self, widget, value):
158 if value < 0:
159 return ValidationError(_("This field cannot be negative"))
160
161 on_freight__validate = _positive_validator
162 on_ipi__validate = _positive_validator
163 on_icms_total__validate = _positive_validator
164 on_secure_value__validate = _positive_validator
165 on_expense_value__validate = _positive_validator
166
126 def on_notes_button__clicked(self, *args):167 def on_notes_button__clicked(self, *args):
127 run_dialog(NoteEditor, self, self.conn, self.model, 'notes',168 run_dialog(NoteEditor, self, self.conn, self.model, 'notes',
128 title=_('Additional Information'))169 title=_('Additional Information'))
129170
130 def on_invoice_number__validate(self, widget, value):171 def on_invoice_number__validate(self, widget, value):
131 if value < 1 or value > 999999:172 if value < 1 or value > 999999:
132 return ValidationError(_("Receving order number must be "173 return ValidationError(_("Receiving order number must be "
133 "between 1 and 999999"))174 "between 1 and 999999"))
134175
135 order_count = ReceivingOrder.selectBy(invoice_number=value,176 order_count = ReceivingOrder.selectBy(invoice_number=value,
@@ -140,15 +181,21 @@
140 return ValidationError(_(u'Invoice %d already exists for '181 return ValidationError(_(u'Invoice %d already exists for '
141 'supplier %s.' % (value, supplier_name,)))182 'supplier %s.' % (value, supplier_name,)))
142183
143 def _positive_validator(self, widget, value):184 def after_freight_combo__content_changed(self, widget):
144 if value < 0:185 value = widget.read()
145 return ValidationError(_("This field cannot be negative"))186
146187 if value == ReceivingOrder.FREIGHT_CIF_UNKNOWN:
147 on_freight__validate = _positive_validator188 self.freight.update(0)
148 on_ipi__validate = _positive_validator189 self.freight.set_sensitive(False)
149 on_icms_total__validate = _positive_validator190 else:
150 on_secure_value__validate = _positive_validator191 if not self.visual_mode:
151 on_expense_value__validate = _positive_validator192 self.freight.set_sensitive(True)
193 if (not self.model.freight_total and
194 value in ReceivingOrder.FOB_FREIGHTS):
195 # Restore the freight value to the purchase expected one.
196 self.freight.update(self.model.purchase.expected_freight)
197
198 self.proxy.update('total')
152199
153 def after_freight__content_changed(self, widget):200 def after_freight__content_changed(self, widget):
154 try:201 try:
@@ -157,7 +204,7 @@
157 value = ValueUnset204 value = ValueUnset
158205
159 if value is ValueUnset:206 if value is ValueUnset:
160 self.model.freight = 0207 self.model.freight_total = 0
161 self.proxy.update('total')208 self.proxy.update('total')
162209
163 def after_ipi__content_changed(self, widget):210 def after_ipi__content_changed(self, widget):

Subscribers

People subscribed via source and target branches