Skip to content

Commit

Permalink
[REF] l10n_br_stock_account:Case without Fiscal OP
Browse files Browse the repository at this point in the history
  • Loading branch information
mbcosta committed Jan 28, 2025
1 parent 2d5c76a commit 449ad28
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions l10n_br_stock_account/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,38 +108,31 @@ def _get_default_fiscal_operation(self):
l10n_br_sale_stock
l10n_br_purchase_stock
"""
company = self.env.company
fiscal_operation = company.stock_fiscal_operation_id
picking_type_id = self.picking_type_id.id
if not picking_type_id:
# Quando isso é necessário? Testes não passam aqui,
# dependendo ver de remover
picking_type_id = self.env.context.get("default_picking_type_id")
if picking_type_id:
picking_type = self.env["stock.picking.type"].browse(picking_type_id)
fiscal_operation = picking_type.fiscal_operation_id or (
company.stock_in_fiscal_operation_id
if picking_type.code == "incoming"
else company.stock_out_fiscal_operation_id
)

return fiscal_operation
if self.env.company.country_id.code == "BR":
fiscal_operation = self.env.company.stock_fiscal_operation_id
picking_type_id = self.picking_type_id.id
if not picking_type_id:
# Quando isso é necessário? Testes não passam aqui,
# dependendo ver de remover
picking_type_id = self.env.context.get("default_picking_type_id")
if picking_type_id:
picking_type = self.env["stock.picking.type"].browse(picking_type_id)
fiscal_operation = picking_type.fiscal_operation_id or (
self.env.company.stock_in_fiscal_operation_id
if picking_type.code == "incoming"
else self.env.company.stock_out_fiscal_operation_id
)

return fiscal_operation

@api.onchange("invoice_state")
def _onchange_invoice_state(self):
result = super()._onchange_invoice_state()
for record in self:
# TODO: Na v16 chamar o super() o update_invoice_state já é
# chamado https://github.com/OCA/account-invoicing/blob/16.0/
# stock_picking_invoicing/models/stock_picking.py#L47
record._update_invoice_state(record.invoice_state)
record.mapped("move_ids")._update_invoice_state(record.invoice_state)

if record.partner_id and record.env.company.country_id == record.env.ref(
"base.br"
):
fiscal_operation = record._get_default_fiscal_operation()
if fiscal_operation:
record.fiscal_operation_id = fiscal_operation
fiscal_operation = record._get_default_fiscal_operation()
if fiscal_operation:
record.fiscal_operation_id = fiscal_operation
return result

def set_to_be_invoiced(self):
"""
Expand Down

0 comments on commit 449ad28

Please sign in to comment.