Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sale_gathering_automation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"sale_gathering",
"sale_order_type_automation",
],
"data": [
"views/sale_order_views.xml",
],
"installable": True,
"auto_install": True,
"application": False,
Expand Down
16 changes: 16 additions & 0 deletions sale_gathering_automation/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
class SaleOrder(models.Model):
_inherit = "sale.order"

def action_create_invoice_with_automation(self):
self.ensure_one()
if (
self.is_gathering
and self.state == "sale"
and self.type_id
and self.type_id.invoicing_atomation != "none"
and self.has_gathering_invoice
and any(line.qty_to_invoice for line in self.order_line)
):
invoices = self.with_context(invoice_gathering=True)._create_invoices(final=True)
self._validate_gathering_invoices(invoices)
return self.action_view_invoice(invoices=invoices)

return self.env.ref("sale.action_view_sale_advance_payment_inv").read()[0]

def run_invoicing_atomation(self):
gathering_lines = self.filtered("is_gathering")
super(SaleOrder, gathering_lines.with_context(invoice_gathering=True)).run_invoicing_atomation()
Expand Down
15 changes: 15 additions & 0 deletions sale_gathering_automation/views/sale_order_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<odoo>
<record id="view_order_form_inherit_gathering_automation" model="ir.ui.view">
<field name="name">sale.order.form.gathering.automation</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<button id="create_invoice" position="after">
<button id="create_invoice_automation" name="action_create_invoice_with_automation" string="Auto Create Invoice"
type="object" groups="account.group_account_invoice"
class="oe_highlight"
invisible="not is_gathering or state != 'sale' or not type_id or type_id.invoicing_atomation == 'none' or not has_gathering_invoice or invoice_status != 'to invoice'"/>
</button>
</field>
</record>
</odoo>