Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
iBiz商业中心
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz商业套件
iBiz商业中心
提交
43b2eecb
提交
43b2eecb
编写于
11月 04, 2020
作者:
yujiaming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
calc_price更新
上级
9cdfdbef
变更
1
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
38 行增加
和
249 行删除
+38
-249
Purchase_order_lineExService.java
...core/extensions/service/Purchase_order_lineExService.java
+38
-249
未找到文件。
businesscentral-core/src/main/java/cn/ibizlab/businesscentral/core/extensions/service/Purchase_order_lineExService.java
浏览文件 @
43b2eecb
package
cn
.
ibizlab
.
businesscentral
.
core
.
extensions
.
service
;
import
cn.ibizlab.businesscentral.core.odoo_account.domain.Account_account_tag
;
import
cn.ibizlab.businesscentral.core.odoo_account.domain.Account_fiscal_position
;
import
cn.ibizlab.businesscentral.core.odoo_account.domain.Account_tax
;
import
cn.ibizlab.businesscentral.core.odoo_base.domain.Res_company
;
import
cn.ibizlab.businesscentral.core.odoo_base.domain.Res_currency
;
import
cn.ibizlab.businesscentral.core.odoo_base.domain.Res_lang
;
import
cn.ibizlab.businesscentral.core.odoo_base.domain.Res_partner
;
import
cn.ibizlab.businesscentral.core.odoo_product.domain.Product_product
;
...
...
@@ -14,7 +11,6 @@ import cn.ibizlab.businesscentral.core.odoo_product.domain.Product_template;
import
cn.ibizlab.businesscentral.core.odoo_purchase.domain.Purchase_order
;
import
cn.ibizlab.businesscentral.core.odoo_purchase.service.impl.Purchase_order_lineServiceImpl
;
import
cn.ibizlab.businesscentral.util.dict.StaticDict
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -68,260 +64,52 @@ public class Purchase_order_lineExService extends Purchase_order_lineServiceImpl
@Override
@Transactional
public
Purchase_order_line
calc_price
(
Purchase_order_line
et
)
{
Map
vals
=
new
HashMap
();
Purchase_order
order
=
purchaseOrderService
.
get
(
et
.
getOrderId
());
vals
.
put
(
"price_unit"
,
et
.
getPriceUnit
());
vals
.
put
(
"currency_id"
,
order
.
getCurrencyId
());
vals
.
put
(
"product_qty"
,
et
.
getProductQty
());
vals
.
put
(
"product"
,
et
.
getProductId
());
vals
.
put
(
"partner"
,
order
.
getPartnerId
());
/**
// account.py中的compute_all()方法, 未处理完成
// 单一税的计算
BigDecimal
priceUnit
=
new
BigDecimal
(
et
.
getPriceUnit
());
BigDecimal
productQty
=
new
BigDecimal
(
et
.
getProductQty
());
// 计算price_subtotal, 小计
BigDecimal
priceSubTotal
=
productQty
.
multiply
(
priceUnit
);
et
.
setPriceSubtotal
(
priceSubTotal
);
JSONArray
jsonArray
=
JSONArray
.
parseArray
(
et
.
getTaxesId
());
Long
taxId
=
jsonArray
.
getJSONObject
(
0
).
getLong
(
"srfkey"
);
Account_tax
accountTax
=
accountTaxService
.
get
(
taxId
);
Long companyId = null;
if(accountTax == null){
companyId = et.getCompanyId();
}else {
companyId = accountTax.getCompanyId();
}
// taxes = self.flatten_taxes_hierarchy(), 未处理
List<Account_tax> taxes = null;
Boolean baseExcludedFlag = false;
Boolean includedFlag = false;
for(Account_tax tax : taxes){
if(tax.getPriceInclude()){
includedFlag = true;
}else if(tax.getIncludeBaseAmount()){
baseExcludedFlag = true;
}
if(baseExcludedFlag && includedFlag){
throw new RuntimeException("无法混合任何税收,包括影响基本金额但不包含在价格中的税收。");
}
}
// 处理币种转换时的舍入
Res_company company = resCompanyService.get(companyId);
Long currencyId = null;
if(vals.get("currency_id") == null){
currencyId = company.getCurrencyId();
}
Res_currency currency = resCurrencyService.get(currencyId);
Double prec = currency.getRounding();
Boolean roundTax = true;
if(StringUtils.compare(company.getTaxCalculationRoundingMethod(), StaticDict.RES_COMPANY__TAX_CALCULATION_ROUNDING_METHOD.ROUND_GLOBALLY.getValue()) == 0){
roundTax = false;
}
Boolean roundTotal = true;
// 未处理
// if 'round' in self.env.context:
// round_tax = bool(self.env.context['round'])
// round_total = bool(self.env.context['round'])
if(!roundTax){
prec *= 1e-5;
}
// recompute_base()方法,未定义
// base = round(price_unit * quantity, precision_rounding=prec), round()方法未处理未处理
Double base = 0.0;
Double sign = 1.0;
if(base <= 0.0){
base = -base;
sign = -1.0;
}
Map totalIncludedCheckpoints = new HashMap();
int i = taxes.size() - 1;
Boolean storeIncludedTaxTotal = true;
Double inclFixedAmount, inclPercentAmount, inclDivisionAmount = 0.0;
Map cachedTaxAmounts = new HashMap();
Collections.reverse(taxes);
for(Account_tax tax : taxes){
// tax_repartition_lines = (
// is_refund
// and tax.refund_repartition_line_ids
// or tax.invoice_repartition_line_ids
// ).filtered(lambda x: x.repartition_type == "tax"), 未处理
List<Long> taxRepartitionLines = null;
// sum_repartition_factor = sum(tax_repartition_lines.mapped("factor"))
Double sumRepartitionFactor = 0.0;
if(tax.getIncludeBaseAmount()){
// base = recompute_base(base, incl_fixed_amount, incl_percent_amount, incl_division_amount, prec) , 未处理
base = null;
inclFixedAmount = inclPercentAmount = inclDivisionAmount = 0.0;
storeIncludedTaxTotal = true;
}
// if tax.price_include or self._context.get('force_price_include'), 未处理
if(tax.getPriceInclude() || ){
if(StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.PERCENT.getValue()) == 0){
inclPercentAmount += tax.getAmount() * sumRepartitionFactor;
}else if(StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.DIVISION.getValue()) == 0){
inclDivisionAmount += tax.getAmount() * sumRepartitionFactor;
}else if(StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.FIXED.getValue()) == 0){
inclFixedAmount += tax.getAmount() * sumRepartitionFactor;
}else{
// tax._compute_amount(base, sign * price_unit, quantity, product, partner) * sum_repartition_factor ,未处理
Double taxAmount = 0.0;
inclFixedAmount += taxAmount;
cachedTaxAmounts.put(i, taxAmount);
}
Boolean condition = StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.PERCENT.getValue()) != 0 && StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.DIVISION.getValue()) != 0 && StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.FIXED.getValue()) != 0;
if(storeIncludedTaxTotal && (tax.getAmount()!=null || condition)){
totalIncludedCheckpoints.put(i, base);
storeIncludedTaxTotal =false;
}
}
i -= 1;
}
// total_excluded = recompute_base(base, incl_fixed_amount, incl_percent_amount, incl_division_amount, prec), 未处理
// 计算不包含税的总计
Double totalExculded = 0.0;
base = totalExculded;
Double totalIncluded = totalExculded;
Double totalVoid = totalExculded;
List<Map> taxesVals = new ArrayList<>();
i = 0;
Double cumulatedTaxIncludedAmount = 0.0;
// 计算price_tax,税率
Double
priceTax
=
null
;
// 固定税
if
(
StringUtils
.
compare
(
accountTax
.
getAmountType
(),
StaticDict
.
ACCOUNT_TAX__AMOUNT_TYPE
.
FIXED
.
getValue
())
==
0
){
//
for(Account_tax tax : taxes){
// tax_repartition_lines = (is_refund and tax.refund_repartition_line_ids or tax.invoice_repartition_line_ids).filtered(lambda x: x.repartition_type == 'tax')
List<Long> taxRepartitionLines = null;
// sum_repartition_factor = sum(tax_repartition_lines.mapped('factor'))
Double sumRepartitionFactor = null;
// price_include = self._context.get('force_price_include', tax.price_include)
Double priceInclude = null;
// 计算taxAmount
Double taxAmount = null;
if(priceInclude != null && totalIncludedCheckpoints.get(i) != null){
taxAmount = (Double)totalIncludedCheckpoints.get(i) - (base + cumulatedTaxIncludedAmount);
cumulatedTaxIncludedAmount = 0.0;
}else {
// tax_amount = tax.with_context(force_price_include=False)._compute_amount(base, sign * price_unit, quantity, product, partner)
// taxAmount = ;
}
// tax_amount = round(tax_amount, precision_rounding=prec)
// 对taxAmount进行四舍五入操作
// factorized_tax_amount = round(tax_amount * sum_repartition_factor, precision_rounding=prec)
Double factorizedTaxAmount = null;
if(priceInclude != null && totalIncludedCheckpoints.get(i) == null) {
// cumulated_tax_included_amount += factorized_tax_amount
cumulatedTaxIncludedAmount += factorizedTaxAmount;
}
// subsequent_taxes = self.env['account.tax']
List<Account_tax> subsequentTaxes = null;
// subsequent_tags = self.env['account.account.tag']
List<Account_account_tag> subsequentTags = null;
if(tax.getIncludeBaseAmount() != null){
// 未处理
// subsequent_taxes = taxes[i+1:]
// subsequent_tags = subsequent_taxes.get_tax_tags(is_refund, 'base')
}
// repartition_line_amounts = [round(tax_amount * line.factor, precision_rounding=prec) for line in tax_repartition_lines]
List repartitionLineAmounts = null;
// total_rounding_error = round(factorized_tax_amount - sum(repartition_line_amounts), precision_rounding=prec)
Double totalRoundingError = null;
// nber_rounding_steps = int(abs(total_rounding_error / currency.rounding))
Integer nberRoundingSteps = (int)Math.abs(totalRoundingError / currency.getRounding());
// rounding_error = round(nber_rounding_steps and total_rounding_error / nber_rounding_steps or 0.0, precision_rounding=prec)
Double roundingError = null;
// for repartition_line, line_amount in zip(tax_repartition_lines, repartition_line_amounts)
for(){
if(nberRoundingSteps != null){
// line_amount += rounding_error
nberRoundingSteps -= 1;
}
Map taxInfo = new HashMap();
taxInfo.put("id", tax.getId());
// partner and tax.with_context(lang=partner.lang).name or tax.name, 未处理
String name = tax.getName();
taxInfo.put("name", name);
// sign * line_amount, 未处理
Double amount = sign * 1;
taxInfo.put("amount", amount);
// round(sign * base, precision_rounding=prec), 未处理
base = null;
taxInfo.put("base", base);
taxInfo.put("sequence", tax.getSequence());
// repartition_line.account_id.id, 未处理
Long accountId = null;
if(StringUtils.compare(tax.getTaxExigibility(), StaticDict.ACCOUNT_TAX__TAX_EXIGIBILITY.ON_PAYMENT.getValue()) == 0){
// tax.cash_basis_transition_account_id.id, 不存在?
accountId = tax.g;
}
taxInfo.put("account_id", accountId);
taxInfo.put("analytic", tax.getAnalytic());
taxInfo.put("price_include", priceInclude);
taxInfo.put("tax_exigibility", tax.getTaxExigibility());
// taxInfo.put("tax_repartition_line_id", );
// taxInfo.put("tag_ids", );
// taxInfo.put("tax_ids", );
taxesVals.add(taxInfo);
// if not repartition_line.account_id:
if(){
// total_void += line_amount
totalVoid += 0;
}
priceTax
=
accountTax
.
getAmount
()
*
productQty
.
doubleValue
();
}
// 价格中是否已经含税
Boolean
priceInclude
=
accountTax
.
getPriceInclude
();
// 价格不含税,税的类型为价格百分比
if
(
StringUtils
.
compare
(
accountTax
.
getAmountType
(),
StaticDict
.
ACCOUNT_TAX__AMOUNT_TYPE
.
PERCENT
.
getValue
())
==
0
&&
!
priceInclude
){
priceTax
=
priceSubTotal
.
doubleValue
()
*
accountTax
.
getAmount
()
/
100
;
}
// 价格含税,税的类型为价格百分比
if
(
StringUtils
.
compare
(
accountTax
.
getAmountType
(),
StaticDict
.
ACCOUNT_TAX__AMOUNT_TYPE
.
PERCENT
.
getValue
())
==
0
&&
priceInclude
){
priceTax
=
priceSubTotal
.
doubleValue
()
-
(
priceSubTotal
.
doubleValue
()
/
(
1
+
accountTax
.
getAmount
()
/
100
));
}
// 价格不含税,税的类型为含税价格百分比
if
(
StringUtils
.
compare
(
accountTax
.
getAmountType
(),
StaticDict
.
ACCOUNT_TAX__AMOUNT_TYPE
.
DIVISION
.
getValue
())
==
0
&&
priceInclude
){
if
((
1
-
accountTax
.
getAmount
()/
100
)
>
0
){
priceTax
=
priceSubTotal
.
doubleValue
()
/
(
1
-
accountTax
.
getAmount
()
/
100
)
-
priceSubTotal
.
doubleValue
();
}
else
{
priceTax
=
0.0
;
}
if(tax.getIncludeBaseAmount() != null){
base += factorizedTaxAmount;
}
totalIncluded += factorizedTaxAmount;
i += 1
;
// 价格含税,税的类型为含税价格百分比
if
(
StringUtils
.
compare
(
accountTax
.
getAmountType
(),
StaticDict
.
ACCOUNT_TAX__AMOUNT_TYPE
.
DIVISION
.
getValue
())
==
0
&&
priceInclude
){
priceTax
=
priceSubTotal
.
doubleValue
()
-
(
priceSubTotal
.
doubleValue
()
*
(
accountTax
.
getAmount
()
/
100
))
;
}
Map result = new HashMap();
// result.put("base_tags", );
result.put("taxes", taxesVals);
result.put("total_excluded", totalExculded);
result.put("total_included", totalIncluded);
result.put("total_void", totalVoid);
*/
// 计算price_subtotal, 小计
BigDecimal
priceSubTotal
=
new
BigDecimal
(
et
.
getPriceUnit
()
*
et
.
getProductQty
());
et
.
setPriceSubtotal
(
priceSubTotal
);
// 计算price_tax,税率
Double
priceTax
=
0.10
*
et
.
getPriceUnit
()
*
et
.
getProductQty
();
et
.
setPriceTax
(
priceTax
);
// 计算price_total, 总计
BigDecimal
priceTotal
=
priceSubTotal
.
add
(
new
BigDecimal
(
priceTax
));
et
.
setPriceTotal
(
priceTotal
);
// this.update(et);
return
super
.
calc_price
(
et
);
}
/**
...
...
@@ -358,24 +146,26 @@ public class Purchase_order_lineExService extends Purchase_order_lineServiceImpl
et
.
setName
(
name
);
// 计算taxid _compute_tax_id
//
Purchase_order
order
=
purchaseOrderService
.
get
(
et
.
getOrderId
());
Long
fpos
=
null
;
if
(
order
.
getFiscalPositionId
()
!=
null
)
{
fpos
=
order
.
getFiscalPositionId
();
}
else
{
// line.order_id.partner_id.with_context(force_company=line.company_id.id).property_account_position_id, 未处理
Res_partner
partner1
=
resPartnerService
.
get
(
order
.
getPartnerId
());
List
<
Account_fiscal_position
>
accountFiscalPositions
=
accountFiscalPositionService
.
selectByCompanyId
(
et
.
getCompanyId
());
}
// 获取当前产品的默认税种
JSONArray
jsonArray
=
new
JSONArray
();
List
<
Product_supplier_taxes_rel
>
productSupplierTaxesRels
=
productSupplierTaxesRelService
.
selectByProdId
(
productTemplate
.
getId
());
// List<Account_tax> taxes = new ArrayList<>();
if
(
productSupplierTaxesRels
.
size
()
!=
0
){
for
(
Product_supplier_taxes_rel
productSupplierTaxesRel
:
productSupplierTaxesRels
){
Account_tax
accountTax
=
accountTaxService
.
get
(
productSupplierTaxesRel
.
getTaxId
());
if
(
accountTax
.
getCompanyId
()
!=
order
.
getCompanyId
()){
productSupplierTaxesRels
.
remove
(
productSupplierTaxesRel
);
}
else
{
// taxes.add(accountTax);
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"srfkey"
,
accountTax
.
getId
());
jsonObject
.
put
(
"srfmajortext"
,
accountTax
.
getName
());
...
...
@@ -385,7 +175,7 @@ public class Purchase_order_lineExService extends Purchase_order_lineServiceImpl
}
if
(
fpos
!=
null
){
// 调用map_tax()方法, 未处理
et
.
setTaxesId
(
"
test
"
);
et
.
setTaxesId
(
""
);
}
else
{
et
.
setTaxesId
(
jsonArray
.
toString
());
}
...
...
@@ -424,7 +214,7 @@ public class Purchase_order_lineExService extends Purchase_order_lineServiceImpl
Map
params
=
new
HashMap
();
params
.
put
(
"order_id"
,
et
.
getOrderId
());
Long
seller
=
null
;
// 未处理,需要调用
product.py
中的_select_seller()方法'
// 未处理,需要调用
产品模块
中的_select_seller()方法'
Product_supplierinfo
supplierinfo
=
supplierinfoService
.
get
(
seller
);
// 判断需不需要重新设置计划日期
...
...
@@ -483,9 +273,8 @@ public class Purchase_order_lineExService extends Purchase_order_lineServiceImpl
et
.
setPriceUnit
(
priceUnit
);
}
// this.create(et);
// 计算税前和税后的总价
et
=
this
.
calc_price
(
et
);
//
et = this.calc_price(et);
}
return
super
.
product_change
(
et
);
}
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录