Browse Source
Merge pull request #123 from beescoop/9.0-procurement-order-cleanup
Merge pull request #123 from beescoop/9.0-procurement-order-cleanup
[ADD] beesdoo_base: cron to cleanup stale procurement orderspull/126/head
Robin Keunen
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 298 additions and 135 deletions
-
45beesdoo_base/__openerp__.py
-
58beesdoo_base/controllers/report.py
-
21beesdoo_base/data/cron.xml
-
4beesdoo_base/models/__init__.py
-
26beesdoo_base/models/membercard.py
-
124beesdoo_base/models/partner.py
-
57beesdoo_base/models/procurement.py
-
1beesdoo_base/wizard/__init__.py
-
47beesdoo_base/wizard/member_card.py
-
14beesdoo_base/wizard/partner.py
-
28beesdoo_base/wizard/portal_wizard.py
@ -1,29 +1,30 @@ |
|||
# -*- coding: utf-8 -*- |
|||
{ |
|||
'name': "Beescoop Base Module", |
|||
|
|||
'summary': """ |
|||
"name": "Beescoop Base Module", |
|||
"summary": """ |
|||
Module that customize the base module and contains some python tools |
|||
""", |
|||
|
|||
'description': """ |
|||
"description": """ |
|||
""", |
|||
|
|||
'author': "Beescoop - Cellule IT", |
|||
'website': "https://github.com/beescoop/Obeesdoo", |
|||
|
|||
'category': 'Project Management', |
|||
'version': '9.0.1.0.1', |
|||
|
|||
'depends': ['point_of_sale', 'purchase', 'report', 'portal', 'partner_firstname'], |
|||
|
|||
'data': [ |
|||
'security/groups.xml', |
|||
'security/ir.model.access.csv', |
|||
'views/partner.xml', |
|||
'wizard/views/member_card.xml', |
|||
'wizard/views/partner.xml', |
|||
'data/default_contact.xml', |
|||
'report/beescard.xml', |
|||
"author": "Beescoop - Cellule IT", |
|||
"website": "https://github.com/beescoop/Obeesdoo", |
|||
"category": "Project Management", |
|||
"version": "9.0.1.0.1", |
|||
"depends": [ |
|||
"point_of_sale", |
|||
"purchase", |
|||
"report", |
|||
"portal", |
|||
"partner_firstname", |
|||
], |
|||
"data": [ |
|||
"security/groups.xml", |
|||
"security/ir.model.access.csv", |
|||
"data/cron.xml", |
|||
"views/partner.xml", |
|||
"wizard/views/member_card.xml", |
|||
"wizard/views/partner.xml", |
|||
"data/default_contact.xml", |
|||
"report/beescard.xml", |
|||
], |
|||
} |
@ -0,0 +1,21 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- |
|||
Copyright 2019 Coop IT Easy |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
--> |
|||
<odoo> |
|||
<data noupdate="0"> |
|||
<record id="cron_cleanup_procurement_order" model="ir.cron"> |
|||
<field name="name">Procurement: cleanup procurement orders blocking the procurement rules</field> |
|||
<field name="active" eval="True"/> |
|||
<field name="user_id" ref="base.user_root"/> |
|||
<field name="interval_number">1</field> |
|||
<field name="interval_type">days</field> |
|||
<field name="numbercall">-1</field> |
|||
<field name="doall" eval="True"/> |
|||
<field name="model">procurement.order</field> |
|||
<field name="function">cron_cleanup_procurement_order</field> |
|||
<field name="args">()</field> |
|||
</record> |
|||
</data> |
|||
</odoo> |
@ -1 +1,3 @@ |
|||
import partner, membercard |
|||
from . import partner |
|||
from . import membercard |
|||
from . import procurement |
@ -0,0 +1,57 @@ |
|||
# Copyright 2019 Coop IT Easy SCRL fs |
|||
# Robin Keunen <robin@coopiteasy.be> |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from openerp import models, fields, api |
|||
import logging |
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
|
|||
class ProcurementOrder(models.Model): |
|||
_inherit = "procurement.order" |
|||
|
|||
@api.model |
|||
def cron_cleanup_procurement_order(self): |
|||
running_procurement = self.env["procurement.order"].search( |
|||
[("state", "=", "running")] |
|||
) |
|||
|
|||
# checks if procurement order is done |
|||
# -> if all moves are 'done' or 'cancel' |
|||
_logger.info("check procurements in running state.") |
|||
running_procurement.check() |
|||
|
|||
# in remaining procurement, cancel those with no procurement order |
|||
unlinked_procurement = self.env["procurement.order"].search( |
|||
[("state", "=", "running"), ("purchase_line_id", "=", False)] |
|||
) |
|||
_logger.info( |
|||
"cancelling %s procurement unlinked from PO." |
|||
% len(unlinked_procurement) |
|||
) |
|||
unlinked_procurement.cancel() |
|||
|
|||
# in remaining procurement, delete those from 'done' purchase order |
|||
procurement_linked_to_done_PO = self.env["procurement.order"].search( |
|||
[ |
|||
("state", "=", "running"), |
|||
("purchase_line_id", "!=", False), |
|||
("purchase_line_id.order_id.state", "=", "done"), |
|||
] |
|||
) |
|||
_logger.info( |
|||
"set %s procurement to done (linked to done PO)" |
|||
% len(procurement_linked_to_done_PO) |
|||
) |
|||
procurement_linked_to_done_PO.write({"state": "done"}) |
|||
|
|||
# cancel procurement order from exceptions |
|||
exception_procurement = self.env["procurement.order"].search( |
|||
[("state", "=", "exception"), ("purchase_line_id", "=", False)] |
|||
) |
|||
_logger.info( |
|||
"cancelling %s procurement in exception" |
|||
% len(exception_procurement) |
|||
) |
|||
exception_procurement.cancel() |
@ -1,2 +1 @@ |
|||
import member_card, partner, portal_wizard |
|||
|
@ -1,52 +1,67 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from openerp import models, fields, api |
|||
|
|||
|
|||
class NewMemberCardWizard(models.TransientModel): |
|||
""" |
|||
A transient model for the creation of a new card. |
|||
The user can only define the raison why a new card is |
|||
needed and the eater/worker that is concerned. |
|||
""" |
|||
_name = 'membercard.new.wizard' |
|||
|
|||
_name = "membercard.new.wizard" |
|||
|
|||
def _get_default_partner(self): |
|||
return self.env.context['active_id'] |
|||
return self.env.context["active_id"] |
|||
|
|||
new_comment = fields.Char('Reason', required=True) |
|||
partner_id = fields.Many2one('res.partner', default=_get_default_partner) |
|||
force_barcode = fields.Char('Force Barcode', groups="beesdoo_base.group_force_barcode") |
|||
new_comment = fields.Char("Reason", required=True) |
|||
partner_id = fields.Many2one("res.partner", default=_get_default_partner) |
|||
force_barcode = fields.Char( |
|||
"Force Barcode", groups="beesdoo_base.group_force_barcode" |
|||
) |
|||
|
|||
@api.one |
|||
def create_new_card(self): |
|||
client = self.partner_id.sudo() |
|||
client._deactivate_active_cards() |
|||
client._new_card(self.new_comment, self.env.uid, barcode=self.force_barcode) |
|||
client._new_card( |
|||
self.new_comment, self.env.uid, barcode=self.force_barcode |
|||
) |
|||
client.member_card_to_be_printed = True |
|||
|
|||
|
|||
class RequestMemberCardPrintingWizard(models.TransientModel): |
|||
|
|||
_name = 'membercard.requestprinting.wizard' |
|||
_name = "membercard.requestprinting.wizard" |
|||
|
|||
def _get_selected_partners(self): |
|||
return self.env.context['active_ids'] |
|||
|
|||
partner_ids = fields.Many2many('res.partner', default=_get_selected_partners) |
|||
return self.env.context["active_ids"] |
|||
|
|||
partner_ids = fields.Many2many( |
|||
"res.partner", default=_get_selected_partners |
|||
) |
|||
|
|||
@api.one |
|||
def request_printing(self): |
|||
self.partner_ids.write({'member_card_to_be_printed' : True}) |
|||
self.partner_ids.write({"member_card_to_be_printed": True}) |
|||
|
|||
|
|||
class SetAsPrintedWizard(models.TransientModel): |
|||
|
|||
_name = 'membercard.set_as_printed.wizard' |
|||
_name = "membercard.set_as_printed.wizard" |
|||
|
|||
def _get_selected_partners(self): |
|||
return self.env.context['active_ids'] |
|||
return self.env.context["active_ids"] |
|||
|
|||
partner_ids = fields.Many2many('res.partner', default=_get_selected_partners) |
|||
partner_ids = fields.Many2many( |
|||
"res.partner", default=_get_selected_partners |
|||
) |
|||
|
|||
@api.one |
|||
def set_as_printed(self): |
|||
self.partner_ids.write({'member_card_to_be_printed' : False, |
|||
'last_printed' : fields.Datetime.now()}) |
|||
self.partner_ids.write( |
|||
{ |
|||
"member_card_to_be_printed": False, |
|||
"last_printed": fields.Datetime.now(), |
|||
} |
|||
) |
@ -1,20 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from openerp import models, fields, api |
|||
|
|||
|
|||
class NewEaterWizard(models.TransientModel): |
|||
""" |
|||
A transient model for the creation of a eater related to a worker. |
|||
""" |
|||
_name = 'eater.new.wizard' |
|||
|
|||
_name = "eater.new.wizard" |
|||
|
|||
def _get_default_partner(self): |
|||
return self.env.context['active_id'] |
|||
return self.env.context["active_id"] |
|||
|
|||
first_name = fields.Char('First Name', required=True) |
|||
last_name = fields.Char('Last Name', required=True) |
|||
email = fields.Char('Email') |
|||
first_name = fields.Char("First Name", required=True) |
|||
last_name = fields.Char("Last Name", required=True) |
|||
email = fields.Char("Email") |
|||
|
|||
partner_id = fields.Many2one('res.partner', default=_get_default_partner) |
|||
partner_id = fields.Many2one("res.partner", default=_get_default_partner) |
|||
|
|||
@api.one |
|||
def create_new_eater(self): |
|||
|
@ -1,26 +1,30 @@ |
|||
from openerp import models, fields, api |
|||
from openerp import SUPERUSER_ID |
|||
|
|||
|
|||
class BeesdooWizard(models.TransientModel): |
|||
|
|||
_inherit = 'portal.wizard' |
|||
_inherit = "portal.wizard" |
|||
|
|||
@api.onchange('portal_id') |
|||
@api.onchange("portal_id") |
|||
def onchange_portal(self): |
|||
# for each partner, determine corresponding portal.wizard.user records |
|||
res_partner = self.env['res.partner'] |
|||
partner_ids = self._context.get('active_ids', []) |
|||
res_partner = self.env["res.partner"] |
|||
partner_ids = self._context.get("active_ids", []) |
|||
|
|||
contact_ids = set() |
|||
for partner in res_partner.browse(partner_ids): |
|||
for contact in (partner.child_ids | partner): |
|||
for contact in partner.child_ids | partner: |
|||
# make sure that each contact appears at most once in the list |
|||
if contact.id not in contact_ids: |
|||
contact_ids.add(contact.id) |
|||
in_portal = self.portal_id in contact.user_ids.mapped('groups_id') |
|||
self.user_ids |= self.env['portal.wizard.user'].new({ |
|||
'partner_id': contact.id, |
|||
'email': contact.email, |
|||
'in_portal': in_portal, |
|||
}) |
|||
|
|||
in_portal = self.portal_id in contact.user_ids.mapped( |
|||
"groups_id" |
|||
) |
|||
self.user_ids |= self.env["portal.wizard.user"].new( |
|||
{ |
|||
"partner_id": contact.id, |
|||
"email": contact.email, |
|||
"in_portal": in_portal, |
|||
} |
|||
) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue