OLD | NEW |
1 #This file is part of Tryton. The COPYRIGHT file at the top level of | 1 #This file is part of Tryton. The COPYRIGHT file at the top level of |
2 #this repository contains the full copyright notices and license terms. | 2 #this repository contains the full copyright notices and license terms. |
3 "Shipment" | 3 "Shipment" |
4 from trytond.model import ModelWorkflow, ModelView, ModelSQL, fields | 4 from trytond.model import ModelWorkflow, ModelView, ModelSQL, fields |
5 from trytond.modules.company import CompanyReport | 5 from trytond.modules.company import CompanyReport |
6 from trytond.wizard import Wizard | 6 from trytond.wizard import Wizard |
7 from trytond.backend import TableHandler | 7 from trytond.backend import TableHandler |
8 from trytond.pyson import Eval, Not, Equal, If, Or, And, Bool, In | 8 from trytond.pyson import Eval, Not, Equal, If, Or, And, Bool, In |
9 | 9 |
10 STATES = { | 10 STATES = { |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 vals = self._get_inventory_moves(cursor, user, incoming_move, | 1282 vals = self._get_inventory_moves(cursor, user, incoming_move, |
1283 context=context) | 1283 context=context) |
1284 if vals: | 1284 if vals: |
1285 self.write(cursor, user, shipment.id, { | 1285 self.write(cursor, user, shipment.id, { |
1286 'inventory_moves': [('create', vals)] | 1286 'inventory_moves': [('create', vals)] |
1287 }, context=context) | 1287 }, context=context) |
1288 | 1288 |
1289 ShipmentOutReturn() | 1289 ShipmentOutReturn() |
1290 | 1290 |
1291 | 1291 |
1292 class AssignShipmentOutAskForce(ModelView): | 1292 class AssignShipmentOutAssignFailed(ModelView): |
1293 'Assign Shipment Out Ask Force' | 1293 'Assign Shipment Out Assign Failed' |
1294 _name = 'stock.shipment.out.assign.ask_force' | 1294 _name = 'stock.shipment.out.assign.assign_failed' |
1295 _description = __doc__ | 1295 _description = __doc__ |
1296 | 1296 |
1297 inventory_moves = fields.Many2Many('stock.move', None, None, | 1297 inventory_moves = fields.Many2Many('stock.move', None, None, |
1298 'Inventory Moves', readonly=True) | 1298 'Inventory Moves', readonly=True) |
1299 | 1299 |
1300 AssignShipmentOutAskForce() | 1300 AssignShipmentOutAssignFailed() |
1301 | 1301 |
1302 | 1302 |
1303 class AssignShipmentOut(Wizard): | 1303 class AssignShipmentOut(Wizard): |
1304 'Assign Shipment Out' | 1304 'Assign Shipment Out' |
1305 _name = 'stock.shipment.out.assign' | 1305 _name = 'stock.shipment.out.assign' |
1306 states = { | 1306 states = { |
1307 'init': { | 1307 'init': { |
1308 'result': { | 1308 'result': { |
1309 'type': 'choice', | 1309 'type': 'choice', |
1310 'next_state': '_choice', | 1310 'next_state': '_choice', |
1311 }, | 1311 }, |
1312 }, | 1312 }, |
| 1313 'assign_failed': { |
| 1314 'actions': ['_moves'], |
| 1315 'result': { |
| 1316 'type': 'form', |
| 1317 'object': 'stock.shipment.out.assign.assign_failed', |
| 1318 'state': [ |
| 1319 ('end', 'Ok', 'tryton-ok', True), |
| 1320 ], |
| 1321 }, |
| 1322 }, |
1313 'ask_force': { | 1323 'ask_force': { |
1314 'actions': ['_moves'], | 1324 'actions': ['_moves'], |
1315 'result': { | 1325 'result': { |
1316 'type': 'form', | 1326 'type': 'form', |
1317 'object': 'stock.shipment.out.assign.ask_force', | 1327 'object': 'stock.shipment.out.assign.assign_failed', |
1318 'state': [ | 1328 'state': [ |
1319 ('force', 'Force Assign', 'tryton-go-next'), | 1329 ('force', 'Force Assign', 'tryton-go-next'), |
1320 ('end', 'Ok', 'tryton-ok', True), | 1330 ('end', 'Ok', 'tryton-ok', True), |
1321 ], | 1331 ], |
1322 }, | 1332 }, |
1323 }, | 1333 }, |
1324 'force': { | 1334 'force': { |
1325 'result': { | 1335 'result': { |
1326 'type': 'action', | 1336 'type': 'action', |
1327 'action': '_force', | 1337 'action': '_force', |
1328 'state': 'end', | 1338 'state': 'end', |
1329 }, | 1339 }, |
1330 }, | 1340 }, |
1331 } | 1341 } |
1332 | 1342 |
1333 def _choice(self, cursor, user, data, context=None): | 1343 def _choice(self, cursor, user, data, context=None): |
1334 shipment_out_obj = self.pool.get('stock.shipment.out') | 1344 shipment_out_obj = self.pool.get('stock.shipment.out') |
| 1345 user_group_obj = self.pool.get('res.user-res.group') |
| 1346 model_data_obj = self.pool.get('ir.model.data') |
| 1347 transition_obj = self.pool.get('workflow.transition') |
1335 | 1348 |
1336 shipment_out_obj.workflow_trigger_validate(cursor, user, data['id'], | 1349 shipment_out_obj.workflow_trigger_validate(cursor, user, data['id'], |
1337 'assign', context=context) | 1350 'assign', context=context) |
1338 shipment = shipment_out_obj.browse(cursor, user, data['id'], | 1351 shipment = shipment_out_obj.browse(cursor, user, data['id'], |
1339 context=context) | 1352 context=context) |
1340 if not [x.id for x in shipment.inventory_moves if x.state == 'draft']: | 1353 if not [x.id for x in shipment.inventory_moves if x.state == 'draft']: |
1341 return 'end' | 1354 return 'end' |
1342 else: | 1355 else: |
1343 return 'ask_force' | 1356 trans_id = model_data_obj.get_id(cursor, user, 'stock', |
| 1357 'shipmentout_trans_waiting_assigned_force', context=context) |
| 1358 trans = transition_obj.read(cursor, user, trans_id, context=context) |
| 1359 user_in_group = user_group_obj.search(cursor, user, [ |
| 1360 ('uid', '=', user), |
| 1361 ('gid', '=', trans['group']), |
| 1362 ], limit=1, context=context) |
| 1363 if user_in_group: |
| 1364 return 'ask_force' |
| 1365 return 'assign_failed' |
1344 | 1366 |
1345 def _moves(self, cursor, user, data, context=None): | 1367 def _moves(self, cursor, user, data, context=None): |
1346 shipment_out_obj = self.pool.get('stock.shipment.out') | 1368 shipment_out_obj = self.pool.get('stock.shipment.out') |
1347 shipment = shipment_out_obj.browse(cursor, user, data['id'], | 1369 shipment = shipment_out_obj.browse(cursor, user, data['id'], |
1348 context=context) | 1370 context=context) |
1349 return {'inventory_moves': [x.id for x in shipment.inventory_moves | 1371 return {'inventory_moves': [x.id for x in shipment.inventory_moves |
1350 if x.state == 'draft']} | 1372 if x.state == 'draft']} |
1351 | 1373 |
1352 def _force(self, cursor, user, data, context=None): | 1374 def _force(self, cursor, user, data, context=None): |
1353 shipment_out_obj = self.pool.get('stock.shipment.out') | 1375 shipment_out_obj = self.pool.get('stock.shipment.out') |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 ShipmentInternal() | 1542 ShipmentInternal() |
1521 | 1543 |
1522 | 1544 |
1523 class Address(ModelSQL, ModelView): | 1545 class Address(ModelSQL, ModelView): |
1524 _name = 'party.address' | 1546 _name = 'party.address' |
1525 delivery = fields.Boolean('Delivery') | 1547 delivery = fields.Boolean('Delivery') |
1526 | 1548 |
1527 Address() | 1549 Address() |
1528 | 1550 |
1529 | 1551 |
1530 class AssignShipmentInternalAskForce(ModelView): | 1552 class AssignShipmentInternalAssignFailed(ModelView): |
1531 'Assign Shipment Internal Ask Force' | 1553 'Assign Shipment Internal Assign Failed' |
1532 _name = 'stock.shipment.internal.assign.ask_force' | 1554 _name = 'stock.shipment.internal.assign.assign_failed' |
1533 _description = __doc__ | 1555 _description = __doc__ |
1534 | 1556 |
1535 moves = fields.Many2Many('stock.move', None, None, 'Moves', | 1557 moves = fields.Many2Many('stock.move', None, None, 'Moves', |
1536 readonly=True) | 1558 readonly=True) |
1537 | 1559 |
1538 AssignShipmentInternalAskForce() | 1560 AssignShipmentInternalAssignFailed() |
1539 | 1561 |
1540 | 1562 |
1541 class AssignShipmentInternal(Wizard): | 1563 class AssignShipmentInternal(Wizard): |
1542 'Assign Shipment Internal' | 1564 'Assign Shipment Internal' |
1543 _name = 'stock.shipment.internal.assign' | 1565 _name = 'stock.shipment.internal.assign' |
1544 states = { | 1566 states = { |
1545 'init': { | 1567 'init': { |
1546 'result': { | 1568 'result': { |
1547 'type': 'choice', | 1569 'type': 'choice', |
1548 'next_state': '_choice', | 1570 'next_state': '_choice', |
1549 }, | 1571 }, |
1550 }, | 1572 }, |
| 1573 'assign_failed': { |
| 1574 'actions': ['_moves'], |
| 1575 'result': { |
| 1576 'type': 'form', |
| 1577 'object': 'stock.shipment.internal.assign.assign_failed', |
| 1578 'state': [ |
| 1579 ('end', 'Ok', 'tryton-ok', True), |
| 1580 ], |
| 1581 }, |
| 1582 }, |
1551 'ask_force': { | 1583 'ask_force': { |
1552 'actions': ['_moves'], | 1584 'actions': ['_moves'], |
1553 'result': { | 1585 'result': { |
1554 'type': 'form', | 1586 'type': 'form', |
1555 'object': 'stock.shipment.internal.assign.ask_force', | 1587 'object': 'stock.shipment.internal.assign.assign_failed', |
1556 'state': [ | 1588 'state': [ |
1557 ('force', 'Force Assign', 'tryton-go-next'), | 1589 ('force', 'Force Assign', 'tryton-go-next'), |
1558 ('end', 'Ok', 'tryton-ok', True), | 1590 ('end', 'Ok', 'tryton-ok', True), |
1559 ], | 1591 ], |
1560 }, | 1592 }, |
1561 }, | 1593 }, |
1562 'force': { | 1594 'force': { |
1563 'result': { | 1595 'result': { |
1564 'type': 'action', | 1596 'type': 'action', |
1565 'action': '_force', | 1597 'action': '_force', |
1566 'state': 'end', | 1598 'state': 'end', |
1567 }, | 1599 }, |
1568 }, | 1600 }, |
1569 } | 1601 } |
1570 | 1602 |
1571 def _choice(self, cursor, user, data, context=None): | 1603 def _choice(self, cursor, user, data, context=None): |
1572 shipment_internal_obj = self.pool.get('stock.shipment.internal') | 1604 shipment_internal_obj = self.pool.get('stock.shipment.internal') |
| 1605 user_group_obj = self.pool.get('res.user-res.group') |
| 1606 model_data_obj = self.pool.get('ir.model.data') |
| 1607 transition_obj = self.pool.get('workflow.transition') |
1573 | 1608 |
1574 shipment_internal_obj.workflow_trigger_validate(cursor, user, | 1609 shipment_internal_obj.workflow_trigger_validate(cursor, user, |
1575 data['id'], 'assign', context=context) | 1610 data['id'], 'assign', context=context) |
1576 shipment = shipment_internal_obj.browse(cursor, user, data['id'], | 1611 shipment = shipment_internal_obj.browse(cursor, user, data['id'], |
1577 context=context) | 1612 context=context) |
1578 if not [x.id for x in shipment.moves if x.state == 'draft']: | 1613 if not [x.id for x in shipment.moves if x.state == 'draft']: |
1579 return 'end' | 1614 return 'end' |
1580 else: | 1615 else: |
1581 return 'ask_force' | 1616 trans_id = model_data_obj.get_id(cursor, user, 'stock', |
| 1617 'shipmentinternal_trans_waiting_assigned_force', |
| 1618 context=context) |
| 1619 trans = transition_obj.read(cursor, user, trans_id, |
| 1620 context=context) |
| 1621 user_in_group = user_group_obj.search(cursor, user, [ |
| 1622 ('uid', '=', user), |
| 1623 ('gid', '=', trans['group']), |
| 1624 ], limit=1, context=context) |
| 1625 if user_in_group: |
| 1626 return 'ask_force' |
| 1627 return 'assign_failed' |
1582 | 1628 |
1583 def _moves(self, cursor, user, data, context=None): | 1629 def _moves(self, cursor, user, data, context=None): |
1584 shipment_internal_obj = self.pool.get('stock.shipment.internal') | 1630 shipment_internal_obj = self.pool.get('stock.shipment.internal') |
1585 shipment = shipment_internal_obj.browse(cursor, user, data['id'], | 1631 shipment = shipment_internal_obj.browse(cursor, user, data['id'], |
1586 context=context) | 1632 context=context) |
1587 return {'moves': [x.id for x in shipment.moves if x.state == 'draft']} | 1633 return {'moves': [x.id for x in shipment.moves if x.state == 'draft']} |
1588 | 1634 |
1589 def _force(self, cursor, user, data, context=None): | 1635 def _force(self, cursor, user, data, context=None): |
1590 shipment_internal_obj = self.pool.get('stock.shipment.internal') | 1636 shipment_internal_obj = self.pool.get('stock.shipment.internal') |
1591 | 1637 |
1592 shipment_internal_obj.workflow_trigger_validate(cursor, user, | 1638 shipment_internal_obj.workflow_trigger_validate(cursor, user, |
1593 data['id'], 'force_assign', context=context) | 1639 data['id'], 'force_assign', context=context) |
1594 return {} | 1640 return {} |
1595 | 1641 |
1596 AssignShipmentInternal() | 1642 AssignShipmentInternal() |
1597 | 1643 |
1598 | 1644 |
1599 class AssignShipmentInReturnAskForce(ModelView): | 1645 class AssignShipmentInReturnAssignFailed(ModelView): |
1600 'Assign Supplier Return Shipment Ask Force' | 1646 'Assign Supplier Return Shipment Assign Failed' |
1601 _name = 'stock.shipment.in.return.assign.ask_force' | 1647 _name = 'stock.shipment.in.return.assign.assign_failed' |
1602 _description = __doc__ | 1648 _description = __doc__ |
1603 | 1649 |
1604 moves = fields.Many2Many('stock.move', None, None, 'Moves', | 1650 moves = fields.Many2Many('stock.move', None, None, 'Moves', |
1605 readonly=True) | 1651 readonly=True) |
1606 | 1652 |
1607 AssignShipmentInReturnAskForce() | 1653 AssignShipmentInReturnAssignFailed() |
1608 | 1654 |
1609 | 1655 |
1610 class AssignShipmentInReturn(Wizard): | 1656 class AssignShipmentInReturn(Wizard): |
1611 'Assign Supplier Return Shipment' | 1657 'Assign Supplier Return Shipment' |
1612 _name = 'stock.shipment.in.return.assign' | 1658 _name = 'stock.shipment.in.return.assign' |
1613 states = { | 1659 states = { |
1614 'init': { | 1660 'init': { |
1615 'result': { | 1661 'result': { |
1616 'type': 'choice', | 1662 'type': 'choice', |
1617 'next_state': '_choice', | 1663 'next_state': '_choice', |
1618 }, | 1664 }, |
1619 }, | 1665 }, |
| 1666 'assign_failed': { |
| 1667 'actions': ['_moves'], |
| 1668 'result': { |
| 1669 'type': 'form', |
| 1670 'object': 'stock.shipment.in.return.assign.assign_failed', |
| 1671 'state': [ |
| 1672 ('end', 'Ok', 'tryton-ok', True), |
| 1673 ], |
| 1674 }, |
| 1675 }, |
1620 'ask_force': { | 1676 'ask_force': { |
1621 'actions': ['_moves'], | 1677 'actions': ['_moves'], |
1622 'result': { | 1678 'result': { |
1623 'type': 'form', | 1679 'type': 'form', |
1624 'object': 'stock.shipment.in.return.assign.ask_force', | 1680 'object': 'stock.shipment.in.return.assign.assign_failed', |
1625 'state': [ | 1681 'state': [ |
1626 ('force', 'Force Assign', 'tryton-go-next'), | 1682 ('force', 'Force Assign', 'tryton-go-next'), |
1627 ('end', 'Ok', 'tryton-ok', True), | 1683 ('end', 'Ok', 'tryton-ok', True), |
1628 ], | 1684 ], |
1629 }, | 1685 }, |
1630 }, | 1686 }, |
1631 'force': { | 1687 'force': { |
1632 'result': { | 1688 'result': { |
1633 'type': 'action', | 1689 'type': 'action', |
1634 'action': '_force', | 1690 'action': '_force', |
1635 'state': 'end', | 1691 'state': 'end', |
1636 }, | 1692 }, |
1637 }, | 1693 }, |
1638 } | 1694 } |
1639 | 1695 |
1640 def _choice(self, cursor, user, data, context=None): | 1696 def _choice(self, cursor, user, data, context=None): |
1641 shipment_internal_obj = self.pool.get('stock.shipment.in.return') | 1697 shipment_internal_obj = self.pool.get('stock.shipment.in.return') |
| 1698 user_group_obj = self.pool.get('res.user-res.group') |
| 1699 model_data_obj = self.pool.get('ir.model.data') |
| 1700 transition_obj = self.pool.get('workflow.transition') |
1642 | 1701 |
1643 shipment_internal_obj.workflow_trigger_validate(cursor, user, | 1702 shipment_internal_obj.workflow_trigger_validate(cursor, user, |
1644 data['id'], 'assign', context=context) | 1703 data['id'], 'assign', context=context) |
1645 shipment = shipment_internal_obj.browse(cursor, user, data['id'], | 1704 shipment = shipment_internal_obj.browse(cursor, user, data['id'], |
1646 context=context) | 1705 context=context) |
1647 if not [x.id for x in shipment.moves if x.state == 'draft']: | 1706 if not [x.id for x in shipment.moves if x.state == 'draft']: |
1648 return 'end' | 1707 return 'end' |
1649 else: | 1708 else: |
1650 return 'ask_force' | 1709 trans_id = model_data_obj.get_id(cursor, user, 'stock', |
| 1710 'shipment_in_return_trans_waiting_assigned_force', |
| 1711 context=context) |
| 1712 trans = transition_obj.read(cursor, user, trans_id, context=context) |
| 1713 user_in_group = user_group_obj.search(cursor, user, [ |
| 1714 ('uid', '=', user), |
| 1715 ('gid', '=', trans['group']), |
| 1716 ], limit=1, context=context) |
| 1717 if user_in_group: |
| 1718 return 'ask_force' |
| 1719 return 'assign_failed' |
1651 | 1720 |
1652 def _moves(self, cursor, user, data, context=None): | 1721 def _moves(self, cursor, user, data, context=None): |
1653 shipment_internal_obj = self.pool.get('stock.shipment.in.return') | 1722 shipment_internal_obj = self.pool.get('stock.shipment.in.return') |
1654 shipment = shipment_internal_obj.browse(cursor, user, data['id'], | 1723 shipment = shipment_internal_obj.browse(cursor, user, data['id'], |
1655 context=context) | 1724 context=context) |
1656 return {'moves': [x.id for x in shipment.moves if x.state == 'draft']} | 1725 return {'moves': [x.id for x in shipment.moves if x.state == 'draft']} |
1657 | 1726 |
1658 def _force(self, cursor, user, data, context=None): | 1727 def _force(self, cursor, user, data, context=None): |
1659 shipment_internal_obj = self.pool.get('stock.shipment.in.return') | 1728 shipment_internal_obj = self.pool.get('stock.shipment.in.return') |
1660 | 1729 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 'to_location_ids' : to_location_ids} | 2019 'to_location_ids' : to_location_ids} |
1951 | 2020 |
1952 | 2021 |
1953 def get_compare_key(self, move, compare_context): | 2022 def get_compare_key(self, move, compare_context): |
1954 from_location_ids = compare_context['from_location_ids'] | 2023 from_location_ids = compare_context['from_location_ids'] |
1955 to_location_ids = compare_context['to_location_ids'] | 2024 to_location_ids = compare_context['to_location_ids'] |
1956 return [from_location_ids.index(move.from_location.id), | 2025 return [from_location_ids.index(move.from_location.id), |
1957 to_location_ids.index(move.to_location.id)] | 2026 to_location_ids.index(move.to_location.id)] |
1958 | 2027 |
1959 InteralShipmentReport() | 2028 InteralShipmentReport() |
OLD | NEW |