Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12.0 imp commown devices add module picking wizard #157

4 changes: 4 additions & 0 deletions commown_devices/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
"views/product.xml",
"views/project_project.xml",
"views/project_task.xml",
"views/project_task_type.xml",
"views/stock_picking.xml",
"views/wizard_crm_lead_picking.xml",
"views/wizard_project_task_picking.xml",
],
"demo": [
"demo/project_task.xml",
],
"installable": True,
}
22 changes: 22 additions & 0 deletions commown_devices/data/action_project_task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
<field name="binding_model_id" ref="project.model_project_task" />
</record>

<record id="action_wizard_project_task_notracking_outward_picking" model="ir.actions.act_window">
<field name="name">[commown] SUPPORT: Send a not tracked product</field>
<field name="src_model">project.task</field>
<field name="res_model">project.task.notracking.outward.picking.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'default_task_id': active_id}</field>
<field name="binding_model_id" ref="project.model_project_task" />
</record>

<record id="action_wizard_project_task_outward_picking" model="ir.actions.act_window">
<field name="name">[commown] SUPPORT: Send a device</field>
<field name="src_model">project.task</field>
Expand All @@ -31,6 +42,17 @@
<field name="binding_model_id" ref="project.model_project_task" />
</record>

<record id="action_wizard_project_task_notracking_inward_picking" model="ir.actions.act_window">
<field name="name">[commown] SUPPORT: Receive a not tracked product</field>
<field name="src_model">project.task</field>
<field name="res_model">project.task.notracking.inward.picking.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'default_task_id': active_id}</field>
<field name="binding_model_id" ref="project.model_project_task" />
</record>

<record id="action_wizard_project_task_inward_picking" model="ir.actions.act_window">
<field name="name">[commown] SUPPORT: Receive a device</field>
<field name="src_model">project.task</field>
Expand Down
8 changes: 4 additions & 4 deletions commown_devices/data/project_task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<odoo>
<data noupdate="1">

<record id="diagnostic_stage" model="project.task.type">
<field name="name">Diagnostic stage</field>
<record id="diagnostic_stage" model="project.task.type">
<field name="name">Diagnostic stage</field>
</record>

<record id="resiliated_stage" model="project.task.type">
<field name="name">Resiliated stage</field>
<record id="resiliated_stage" model="project.task.type">
<field name="name">Resiliated stage</field>
</record>

</data>
Expand Down
15 changes: 15 additions & 0 deletions commown_devices/demo/project_task.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<odoo>
<data>

<record id="picking_sent" model="project.task.type">
<field name="name">Picking sent stage</field>
<field name="check_picking_assigned" eval="True"/>
</record>

<record id="sup_picking_ongoing_stage" model="project.task.type">
<field name="name">Picking ongoing stage</field>
<field name="check_picking_assigned" eval="True"/>
</record>

</data>
</odoo>
167 changes: 126 additions & 41 deletions commown_devices/i18n/fr.po

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions commown_devices/models/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,65 @@
from odoo import fields


def internal_picking_tracking_none(
origin, products, orig_location, dest_location, date=None, do_transfer=False
):
env = orig_location.env
picking_type = env.ref("stock.picking_type_internal")

date = date or fields.Datetime.now()

picking = env["stock.picking"].create(
{
"move_type": "direct",
"picking_type_id": picking_type.id,
"location_id": orig_location.id,
"location_dest_id": dest_location.id,
"date": date,
"date_done": date,
"origin": origin,
}
)

moves = {}
for product, quantity in products.items():
moves[product] = env["stock.move"].create(
{
"name": product.name,
"picking_id": picking.id,
"picking_type_id": picking_type.id,
"location_id": orig_location.id,
"location_dest_id": dest_location.id,
"product_id": product.id,
"product_uom_qty": quantity,
"product_uom": product.uom_id.id,
"date": date,
}
)

picking.scheduled_date = date

assert picking.move_lines
picking.action_confirm()
picking.action_assign()
assert picking.state == "assigned", (
"Cannot assign any device: state keeps: %r" % picking.state
)

for product, move in moves.items():
move.move_line_ids.update(
{
"location_id": orig_location.id,
"qty_done": products[product],
}
)

if do_transfer:
do_new_transfer(picking, date)

Check warning on line 58 in commown_devices/models/common.py

View check run for this annotation

Codecov / codecov/patch

commown_devices/models/common.py#L58

Added line #L58 was not covered by tests

return picking


def internal_picking(
origin, lots, orig_location, dest_location, date=None, do_transfer=False
):
Expand Down
113 changes: 107 additions & 6 deletions commown_devices/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from collections import OrderedDict

from odoo import _, api, fields, models
from odoo.exceptions import UserError

from .common import internal_picking
from .common import internal_picking, internal_picking_tracking_none

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,40 +45,140 @@
record.quant_nb = len(record.quant_ids)

@api.multi
def send_device(self, quant, date=None, do_transfer=False):
def send_device(self, quant, origin=None, date=None, do_transfer=False):
"""Create a picking of quant to partner's location.
If given `date` is falsy (the default), it is set to now.
If `do_transfer` is True (default: False), execute the picking
at the previous date.
"""
dest_location = self.partner_id.get_or_create_customer_location()
if origin is None:
origin = self.name
return self._create_picking(
[quant.lot_id],
quant.location_id,
dest_location,
origin=origin,
date=date,
do_transfer=do_transfer,
)

@api.multi
def receive_device(self, lot, dest_location, date=False, do_transfer=False):
def send_device_tracking_none(
self, product, origin=None, date=None, do_transfer=False
):
"""Create a picking of quant to partner's location.
If given `date` is falsy (the default), it is set to now.
If `do_transfer` is True (default: False), execute the picking
at the previous date.
"""
stock = self.env.ref("stock.stock_location_stock")
dest_location = self.partner_id.get_or_create_customer_location()
quant = self.env["stock.quant"].search(
[
("product_id", "=", product.id),
("location_id", "child_of", stock.id),
("quantity", ">", 0),
]
)
if origin is None:
origin = self.name

Check warning on line 85 in commown_devices/models/contract.py

View check run for this annotation

Codecov / codecov/patch

commown_devices/models/contract.py#L85

Added line #L85 was not covered by tests
fcayre marked this conversation as resolved.
Show resolved Hide resolved
if not quant:
raise UserError(_("No product %s found in stock") % product.name)

Check warning on line 87 in commown_devices/models/contract.py

View check run for this annotation

Codecov / codecov/patch

commown_devices/models/contract.py#L87

Added line #L87 was not covered by tests

return self._create_picking_tracking_none(
{product: 1},
quant.location_id,
dest_location,
origin=origin,
date=date,
do_transfer=do_transfer,
)

@api.multi
def receive_device(
self, lot, dest_location, origin=None, date=False, do_transfer=False
):
"""Create a picking from partner's location to `dest_location`.
If given `date` is falsy (the default), it is set to now.
If `do_transfer` is True (default: False), execute the picking
at the previous date.
"""
if origin is None:
origin = self.name
fcayre marked this conversation as resolved.
Show resolved Hide resolved

orig_location = self.partner_id.get_or_create_customer_location()
return self._create_picking(
[lot], orig_location, dest_location, date=date, do_transfer=do_transfer
[lot],
orig_location,
dest_location,
origin=origin,
date=date,
do_transfer=do_transfer,
)

@api.multi
def receive_device_tracking_none(
self, product, dest_location, origin=None, date=False, do_transfer=False
):
"""Create a picking from partner's location to `dest_location`.
If given `date` is falsy (the default), it is set to now.
If `do_transfer` is True (default: False), execute the picking
at the previous date.
"""

if origin is None:
origin = self.name

Check warning on line 131 in commown_devices/models/contract.py

View check run for this annotation

Codecov / codecov/patch

commown_devices/models/contract.py#L131

Added line #L131 was not covered by tests
fcayre marked this conversation as resolved.
Show resolved Hide resolved

orig_location = self.partner_id.get_or_create_customer_location()
return self._create_picking_tracking_none(
{product: 1},
orig_location,
dest_location,
origin=origin,
date=date,
do_transfer=do_transfer,
)

def _create_picking_tracking_none(
self,
products,
orig_location,
dest_location,
origin=None,
date=None,
do_transfer=False,
):
self.ensure_one()

if origin is None:
origin = self.name

Check warning on line 155 in commown_devices/models/contract.py

View check run for this annotation

Codecov / codecov/patch

commown_devices/models/contract.py#L155

Added line #L155 was not covered by tests
fcayre marked this conversation as resolved.
Show resolved Hide resolved
picking = internal_picking_tracking_none(
origin,
products,
orig_location,
dest_location,
date=date,
do_transfer=do_transfer,
)
self.picking_ids |= picking

return picking

def _create_picking(
self, lots, orig_location, dest_location, date=None, do_transfer=False
self,
lots,
orig_location,
dest_location,
origin=None,
date=None,
do_transfer=False,
):
self.ensure_one()
if origin is None:
origin = self.name

Check warning on line 179 in commown_devices/models/contract.py

View check run for this annotation

Codecov / codecov/patch

commown_devices/models/contract.py#L179

Added line #L179 was not covered by tests
fcayre marked this conversation as resolved.
Show resolved Hide resolved
picking = internal_picking(
self.name,
origin,
lots,
orig_location,
dest_location,
Expand Down
14 changes: 5 additions & 9 deletions commown_devices/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CrmLead(models.Model):
def action_generate_picking(self):
contract = self.contract_id

if contract.picking_ids.filtered(lambda p: p.state == "assigned"):
if contract.picking_ids.filtered(_assigned):
raise UserError(
_(
"The contract has already assigned picking(s)!\n"
Expand All @@ -36,15 +36,11 @@ def action_generate_picking(self):
"context": {"default_lead_id": self.id},
}

@api.multi
def write(self, values):
res = super().write(values)
stage_id = values.get("stage_id")
if stage_id:
stage = self.env["crm.stage"].browse(stage_id)
if "[stock: check-has-picking]" in stage.name:
@api.constrains("stage_id")
def _check_picking_on_stage_change(self):
if self.stage_id.name:
if "[stock: check-has-picking]" in self.stage_id.name:
self.action_check_waiting_picking()
return res

def action_check_waiting_picking(self):
if self.so_line_id.product_id.product_tmpl_id.storable_product_id:
Expand Down
Loading
Loading