Skip to content

Commit

Permalink
[13.0][FIX] Add acconut_invoicing_mode
Browse files Browse the repository at this point in the history
Add few changes from reviews.
Use sudo to post the invoice.
  • Loading branch information
TDu committed Sep 22, 2020
1 parent 2ce3764 commit 2433312
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class AccountMove(models.Model):
@job(default_channel="root.invoice_validation")
@related_action(action="related_action_open_invoice")
def _validate_invoice(self):
return self.action_post()
return self.sudo().action_post()
4 changes: 1 addition & 3 deletions account_invoice_base_invoicing_mode/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
class SaleOrder(models.Model):
_inherit = "sale.order"

invoicing_mode = fields.Selection(
related="partner_invoice_id.invoicing_mode", readonly=True
)
invoicing_mode = fields.Selection(related="partner_invoice_id.invoicing_mode")
26 changes: 15 additions & 11 deletions account_invoice_mode_at_shipping/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@ class StockPicking(models.Model):

def action_done(self):
res = super().action_done()
picking_to_invoice = self.filtered(
lambda r: r.sale_id.partner_invoice_id.invoicing_mode == "at_shipping"
and r.picking_type_code == "outgoing"
)
for picking in picking_to_invoice:
picking.with_delay()._invoicing_at_shipping()

for picking in self:
if picking._invoice_at_shipping():
picking.with_delay()._invoicing_at_shipping()
return res

def _invoice_at_shipping(self):
"""Check if picking must be invoiced at shipping."""
self.ensure_one()
return (
self.picking_type_code == "outgoing"
and self.sale_id.partner_invoice_id.invoicing_mode == "at_shipping"
)

@job(default_channel="root.invoice_at_shipping")
def _invoicing_at_shipping(self):
self.ensure_one()
sale_order_ids = self._get_sales_order_to_invoice()
partner = sale_order_ids.partner_invoice_id
invoices = sale_order_ids._create_invoices(
grouped=partner.one_invoice_per_order
)
sales_order = self._get_sales_order_to_invoice()
partner = sales_order.partner_invoice_id
invoices = sales_order._create_invoices(grouped=partner.one_invoice_per_order)
for invoice in invoices:
invoice.with_delay()._validate_invoice()
return invoices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class TestInvoiceModeAtShipping(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.partner = cls.env.ref("base.res_partner_1")
cls.product = cls.env.ref("product.product_delivery_01")
cls.so1 = cls.env["sale.order"].create(
Expand Down Expand Up @@ -66,7 +67,7 @@ def test_invoice_created_at_shipping(self):
self.assertEqual(self.so1.invoice_ids.state, "posted")

def test_invoice_not_created_at_shipping(self):
"""Check that an invoice is created when goods are shipped."""
"""Check that an invoice is not created when goods are shipped."""
self.partner.invoicing_mode = "standard"
self.so1.action_confirm()
for picking in self.so1.picking_ids:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TestInvoiceModeMonthly(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.SaleOrder = cls.env["sale.order"]
cls.partner = cls.env.ref("base.res_partner_1")
cls.partner.invoicing_mode = "monthly"
Expand Down

0 comments on commit 2433312

Please sign in to comment.