first commit
This commit is contained in:
2
modules/account_stock_shipment_cost_weight/__init__.py
Normal file
2
modules/account_stock_shipment_cost_weight/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
36
modules/account_stock_shipment_cost_weight/account.py
Normal file
36
modules/account_stock_shipment_cost_weight/account.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from decimal import Decimal
|
||||
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
|
||||
class ShipmentCost(metaclass=PoolMeta):
|
||||
__name__ = 'account.shipment_cost'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.allocation_method.selection.append(('weight', "By Weight"))
|
||||
|
||||
def allocate_cost_by_weight(self):
|
||||
self.factors = self._get_factors('weight')
|
||||
self._allocate_cost(self.factors)
|
||||
|
||||
def unallocate_cost_by_weight(self):
|
||||
factors = self.factors or self._get_factors('weight')
|
||||
self._allocate_cost(factors, sign=-1)
|
||||
|
||||
def _get_weight_factors(self):
|
||||
"Return the factor for each shipment based on weight"
|
||||
shipments = self.all_shipments
|
||||
sum_weight = sum(Decimal(s.weight or 0) for s in shipments)
|
||||
length = Decimal(len(shipments))
|
||||
factors = {}
|
||||
for shipment in shipments:
|
||||
if not sum_weight:
|
||||
factors[str(shipment)] = 1 / length
|
||||
else:
|
||||
factors[str(shipment)] = (
|
||||
Decimal(shipment.weight or 0) / sum_weight)
|
||||
return factors
|
||||
7
modules/account_stock_shipment_cost_weight/locale/bg.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/bg.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/ca.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/ca.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Per pes"
|
||||
7
modules/account_stock_shipment_cost_weight/locale/cs.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/cs.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/de.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/de.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Nach Gewicht"
|
||||
7
modules/account_stock_shipment_cost_weight/locale/es.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/es.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Por peso"
|
||||
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/et.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/et.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/fa.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/fa.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/fi.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/fi.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/fr.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/fr.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Par poids"
|
||||
7
modules/account_stock_shipment_cost_weight/locale/hu.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/hu.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/id.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/id.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/it.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/it.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Per peso"
|
||||
7
modules/account_stock_shipment_cost_weight/locale/lo.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/lo.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/lt.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/lt.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/nl.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/nl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Per Gewicht"
|
||||
7
modules/account_stock_shipment_cost_weight/locale/pl.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/pl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/pt.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/pt.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
8
modules/account_stock_shipment_cost_weight/locale/ro.po
Normal file
8
modules/account_stock_shipment_cost_weight/locale/ro.po
Normal file
@@ -0,0 +1,8 @@
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "După Greutate"
|
||||
7
modules/account_stock_shipment_cost_weight/locale/ru.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/ru.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/sl.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/sl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/tr.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/tr.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_shipment_cost_weight/locale/uk.po
Normal file
7
modules/account_stock_shipment_cost_weight/locale/uk.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.shipment_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,170 @@
|
||||
===========================================
|
||||
Account Stock Shipment Cost Weight Scenario
|
||||
===========================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... 'account_stock_shipment_cost_weight', create_company, create_chart)
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ShipmentOut = Model.get('stock.shipment.out')
|
||||
>>> ShipmentCost = Model.get('account.shipment_cost')
|
||||
|
||||
Get company::
|
||||
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(today=today))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer.save()
|
||||
>>> carrier = Party(name="Carrier")
|
||||
>>> carrier.save()
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = accounts['expense']
|
||||
>>> account_category.account_revenue = accounts['revenue']
|
||||
>>> account_category.save()
|
||||
|
||||
Create products::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', "Unit")])
|
||||
>>> kg, = ProductUom.find([('name', '=', 'Kilogram')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('100.00')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.weight_uom = kg
|
||||
>>> template.weight = 10
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Shipment Cost"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.shipment_cost = True
|
||||
>>> template.list_price = Decimal('4.00')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product_shipment_cost, = template.products
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> warehouse_loc, = Location.find([('code', '=', 'WH')])
|
||||
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
|
||||
>>> output_loc, = Location.find([('code', '=', 'OUT')])
|
||||
>>> storage_loc, = Location.find([('code', '=', 'STO')])
|
||||
|
||||
Ship 20 units of the product in two shipments::
|
||||
|
||||
>>> shipment1 = ShipmentOut()
|
||||
>>> shipment1.customer = customer
|
||||
>>> shipment1.cost_edit = True
|
||||
>>> shipment1.cost_used = Decimal('4.00')
|
||||
>>> shipment1.cost_currency_used = company.currency
|
||||
>>> move = shipment1.outgoing_moves.new()
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 15
|
||||
>>> move.from_location = output_loc
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.unit_price = Decimal('100.00')
|
||||
>>> move.currency = company.currency
|
||||
>>> shipment1.click('wait')
|
||||
>>> shipment1.click('assign_force')
|
||||
>>> shipment1.click('pick')
|
||||
>>> shipment1.click('pack')
|
||||
>>> shipment1.click('do')
|
||||
>>> shipment1.state
|
||||
'done'
|
||||
|
||||
>>> shipment2, = shipment1.duplicate()
|
||||
>>> move, = shipment2.outgoing_moves
|
||||
>>> move.quantity = 5
|
||||
>>> shipment2.click('wait')
|
||||
>>> shipment2.click('assign_force')
|
||||
>>> shipment2.click('pick')
|
||||
>>> shipment2.click('pack')
|
||||
>>> shipment2.click('do')
|
||||
>>> shipment2.state
|
||||
'done'
|
||||
|
||||
Invoice shipment cost::
|
||||
|
||||
>>> invoice = Invoice(type='in')
|
||||
>>> invoice.party = carrier
|
||||
>>> invoice.invoice_date = today
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.product = product_shipment_cost
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('20.00')
|
||||
>>> invoice.click('post')
|
||||
>>> invoice.state
|
||||
'posted'
|
||||
|
||||
Add shipment cost to both shipments::
|
||||
|
||||
>>> shipment_cost = ShipmentCost(allocation_method='weight')
|
||||
>>> shipment_cost.invoice_lines.extend(
|
||||
... shipment_cost.invoice_lines.find([]))
|
||||
>>> shipment_cost.shipments.extend(
|
||||
... shipment_cost.shipments.find([]))
|
||||
>>> shipment_cost.save()
|
||||
>>> shipment_cost.state
|
||||
'draft'
|
||||
>>> post_shipment_cost = shipment_cost.click('post_wizard')
|
||||
>>> post_shipment_cost.form.cost
|
||||
Decimal('20.0000')
|
||||
>>> sorted([s.cost for s in post_shipment_cost.form.shipments])
|
||||
[Decimal('5.0000'), Decimal('15.0000')]
|
||||
>>> post_shipment_cost.execute('post')
|
||||
>>> shipment_cost.state
|
||||
'posted'
|
||||
>>> bool(shipment_cost.posted_date)
|
||||
True
|
||||
|
||||
Check shipment cost::
|
||||
|
||||
>>> shipment1.reload()
|
||||
>>> shipment1.cost
|
||||
Decimal('15.0000')
|
||||
>>> shipment2.reload()
|
||||
>>> shipment2.cost
|
||||
Decimal('5.0000')
|
||||
@@ -0,0 +1,12 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class AccountStockShipmentCostWeightTestCase(ModuleTestCase):
|
||||
'Test Account Stock Shipment Cost Weight module'
|
||||
module = 'account_stock_shipment_cost_weight'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
@@ -0,0 +1,8 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
10
modules/account_stock_shipment_cost_weight/tryton.cfg
Normal file
10
modules/account_stock_shipment_cost_weight/tryton.cfg
Normal file
@@ -0,0 +1,10 @@
|
||||
[tryton]
|
||||
version=7.8.0
|
||||
depends:
|
||||
account_stock_shipment_cost
|
||||
ir
|
||||
stock_shipment_measurements
|
||||
|
||||
[register]
|
||||
model:
|
||||
account.ShipmentCost
|
||||
Reference in New Issue
Block a user