summaryrefslogtreecommitdiff
path: root/fixco_custom/models
diff options
context:
space:
mode:
Diffstat (limited to 'fixco_custom/models')
-rwxr-xr-xfixco_custom/models/__init__.py1
-rw-r--r--fixco_custom/models/purchase_order.py12
-rw-r--r--fixco_custom/models/purchase_order_multi_bills.py62
-rwxr-xr-xfixco_custom/models/sale.py1
-rw-r--r--fixco_custom/models/upload_cancel_picking.py6
-rw-r--r--fixco_custom/models/upload_ginee.py1
6 files changed, 82 insertions, 1 deletions
diff --git a/fixco_custom/models/__init__.py b/fixco_custom/models/__init__.py
index c13c9a3..0068d32 100755
--- a/fixco_custom/models/__init__.py
+++ b/fixco_custom/models/__init__.py
@@ -38,3 +38,4 @@ from . import account_move_reversal
from . import upload_cancel_picking
from . import product_supplierinfo
from . import queue_job
+from . import purchase_order_multi_bills \ No newline at end of file
diff --git a/fixco_custom/models/purchase_order.py b/fixco_custom/models/purchase_order.py
index 43fe8f6..c745fbe 100644
--- a/fixco_custom/models/purchase_order.py
+++ b/fixco_custom/models/purchase_order.py
@@ -58,6 +58,18 @@ class PurchaseOrder(models.Model):
soo_tax = fields.Float('SOO Tax', copy=False)
discount_total = fields.Float('Discount Total', help = 'Total Discount for Each Product', copy=False, default=0.0)
+ def open_form_multi_create_bills(self):
+ return {
+ 'name': _('Create Bills'),
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'purchase.order.multi_bills',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'context': {
+ 'po_ids': self.ids,
+ }
+ }
+
def _get_fixco_token(self, source='auto'):
ICP = self.env['ir.config_parameter'].sudo()
TokenLog = self.env['token.log'].sudo()
diff --git a/fixco_custom/models/purchase_order_multi_bills.py b/fixco_custom/models/purchase_order_multi_bills.py
new file mode 100644
index 0000000..d9e3c0d
--- /dev/null
+++ b/fixco_custom/models/purchase_order_multi_bills.py
@@ -0,0 +1,62 @@
+from odoo import models, fields, api, _
+from odoo.exceptions import UserError
+
+class PurchaeOrderMultiBills(models.TransientModel):
+ _name = 'purchase.order.multi_bills'
+ _description = 'Create bills for Multiple purchases Orders'
+
+ def queue_job(self):
+ po_ids = self._context.get('po_ids', [])
+ purchase_orders = self.env['purchase.order'].browse(po_ids)
+ for purchase in purchase_orders:
+ queue_job = self.env['queue.job'].search([('res_id', '=', purchase.id), ('method_name', '=', 'create_bills')], limit=1)
+ if queue_job:
+ continue
+ self.env['queue.job'].create({
+ 'name': f'Create Bills {purchase.name}',
+ 'model_name': 'purchase.order',
+ 'method_name': 'action_create_invoice',
+ 'res_id': purchase.id,
+ })
+
+ # def create_bills(self):
+ # # Get SO IDs from context
+ # po_ids = self._context.get('po_ids', [])
+ # if not po_ids:
+ # raise UserError(_("No purchases orders selected!"))
+
+ # # Browse all selected purchases orders
+ # purchase_orders = self.env['purchase.order'].browse(po_ids)
+ # created_bills = self.env['account.move']
+
+ # # Create one invoice per SO (even if partner is the same)
+ # for order in purchase_orders:
+ # # Create invoice for this SO only
+ # invoice = order.with_context(default_invoice_origin=order.name)._create_bills(final=True)
+ # invoice.action_post()
+ # created_bills += invoice
+
+ # # Link the invoice to the SO
+ # order.invoice_ids += invoice
+
+ # # Return action to view created bills
+ # if len(created_bills) > 1:
+ # action = {
+ # 'name': _('Created bills'),
+ # 'type': 'ir.actions.act_window',
+ # 'res_model': 'account.move',
+ # 'view_mode': 'tree,form',
+ # 'domain': [('id', 'in', created_bills.ids)],
+ # }
+ # elif created_bills:
+ # action = {
+ # 'name': _('Created Invoice'),
+ # 'type': 'ir.actions.act_window',
+ # 'res_model': 'account.move',
+ # 'view_mode': 'form',
+ # 'res_id': created_bills.id,
+ # }
+ # else:
+ # action = {'type': 'ir.actions.act_window_close'}
+
+ # return action \ No newline at end of file
diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py
index 8b04538..cd5f68f 100755
--- a/fixco_custom/models/sale.py
+++ b/fixco_custom/models/sale.py
@@ -25,6 +25,7 @@ class SaleOrder(models.Model):
# Create invoice for this SO only
invoice = order.with_context(default_invoice_origin=order.name)._create_invoices(final=True)
invoice.action_post()
+ invoice.invoice_date = invoice.picking_id.date_done
created_invoices += invoice
# Link the invoice to the SO
diff --git a/fixco_custom/models/upload_cancel_picking.py b/fixco_custom/models/upload_cancel_picking.py
index b4038bf..54a94d5 100644
--- a/fixco_custom/models/upload_cancel_picking.py
+++ b/fixco_custom/models/upload_cancel_picking.py
@@ -144,9 +144,13 @@ class UploadCancelPicking(models.Model):
}
def action_cancel_picking(self):
+ self.date_upload = datetime.utcnow()
for line in self.picking_lines:
+ queue_job = self.env['queue.job'].search([('res_id', '=', line.id), ('method_name', '=', 'cancel_picking')], limit=1)
+ if queue_job:
+ continue
self.env['queue.job'].create({
- 'name': f'Cancel Picking {line.name}',
+ 'name': f'Cancel Picking {line.picking_id.name}',
'model_name': 'upload.cancel.picking.line',
'method_name': 'cancel_picking',
'res_id': line.id,
diff --git a/fixco_custom/models/upload_ginee.py b/fixco_custom/models/upload_ginee.py
index 4341269..282bf74 100644
--- a/fixco_custom/models/upload_ginee.py
+++ b/fixco_custom/models/upload_ginee.py
@@ -167,6 +167,7 @@ class UploadGinee(models.Model):
# self.ginee_lines.create_so_and_detail_order()
def action_get_order_id_and_create_detail_order(self):
+ self.date_upload = datetime.utcnow()
for line in self.ginee_lines:
queue_job = self.env['queue.job'].search([('res_id', '=', line.id), ('method_name', '=', 'get_order_id_and_create_detail_order')], limit=1)
if queue_job: