Skip to content

Commit

Permalink
[IMP] Reserve document number on picking pack operation
Browse files Browse the repository at this point in the history
  • Loading branch information
mileo committed May 27, 2024
1 parent 7cda30b commit 5255cb3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
21 changes: 21 additions & 0 deletions l10n_br_stock_account/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,24 @@ def fields_view_get(
}

return order_view

def _put_in_pack(self, move_line_ids, create_package_level=True):
package = super()._put_in_pack(move_line_ids, create_package_level)

Check warning on line 92 in l10n_br_stock_account/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_stock_account/models/stock_picking.py#L92

Added line #L92 was not covered by tests

# [x]. Número da nota fiscal e série;
# [x] Salvar informação no picking;
# [x] Adaptar wizard para copiar essas informações para a fatura;
# [x] Verificar que ao confirmar a fatura um nº não é gerado novamente;
# 5. Colocar a informação do nº e série na etiqueta;

if self.company_id.document_type_id and self.fiscal_operation_id:
# 6. Deixar esta opção configurável por operação fiscal ou por picking type?

self.document_type_id = self.company_id.document_type_id
self.document_serie_id = self.document_type_id.get_document_serie(

Check warning on line 104 in l10n_br_stock_account/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_stock_account/models/stock_picking.py#L103-L104

Added lines #L103 - L104 were not covered by tests
self.company_id, self.fiscal_operation_id
)
self.document_serie = self.document_serie_id.code
self.document_number = self.document_serie_id.next_seq_number()

Check warning on line 108 in l10n_br_stock_account/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_stock_account/models/stock_picking.py#L107-L108

Added lines #L107 - L108 were not covered by tests

return package

Check warning on line 110 in l10n_br_stock_account/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_stock_account/models/stock_picking.py#L110

Added line #L110 was not covered by tests
20 changes: 20 additions & 0 deletions l10n_br_stock_account/views/stock_picking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,26 @@

</group>
</xpath>
<xpath expr="//page[@name='page_invoicing']" position="inside">
<!-- Estes campos são read only momentaneamente, pode ser que em
um segundo momento essas informações também sejam relevantes para
pickings de entrada com relação com documentos fiscais ainda não
importados no sistema.
-->
<group name="document_info" string="Fiscal Document Info">
<field name="document_key" readonly="1" />
</group>
<group>
<group>
<field name="document_type_id" readonly="1" />
<field name="document_serie_id" readonly="1" />
</group>
<group>
<field name="document_serie" readonly="1" />
<field name="document_number" readonly="1" />
</group>
</group>
</xpath>
</field>
</record>

Expand Down
22 changes: 12 additions & 10 deletions l10n_br_stock_account/wizards/stock_invoice_onshipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,18 @@ def _build_invoice_values_from_pickings(self, pickings):

fiscal_vals = picking._prepare_br_fiscal_dict()

document_type = picking.company_id.document_type_id
document_type_id = picking.company_id.document_type_id.id

fiscal_vals["document_type_id"] = document_type_id

document_serie = document_type.get_document_serie(
picking.company_id, picking.fiscal_operation_id
)
if document_serie:
fiscal_vals["document_serie_id"] = document_serie.id
if not fiscal_vals.get("document_type_id"):
# não sobrescreve os dados caso ás informações já tenham sido geradas
# nó método _put_in_pack
document_type_id = picking.company_id.document_type_id

fiscal_vals["document_type_id"] = document_type_id.id

document_serie = document_type_id.get_document_serie(
picking.company_id, picking.fiscal_operation_id
)
if document_serie:
fiscal_vals["document_serie_id"] = document_serie.id

if picking.fiscal_operation_id and picking.fiscal_operation_id.journal_id:
fiscal_vals["journal_id"] = picking.fiscal_operation_id.journal_id.id
Expand Down

0 comments on commit 5255cb3

Please sign in to comment.